Posted March 10, 20232 yr I am implementing a custom projectile that simply goes in a straight line. Nearly everything about my custom projectile works, except the rotation. I want the projectile to rotate in the direction it is going, like an arrow. This is my source code below. public class CustomProjectileEntity extends Projectile implements GeoAnimatable { private double shooterX; private double shooterY; private double shooterZ; // Constructor is placed here; shooterX, shooterY, and shooterZ are initialized public void shoot(LivingEntity target, float velocity) { double xDir = target.getX() - this.shooterX; double yDir = target.getY() - this.shooterY; double zDir = target.getZ() - this.shooterZ; this.shoot(xDir, yDir, zDir, velocity, 0.0f); } public void tick() { super.tick(); // ... Vec3 vec3 = this.getDeltaMovement(); double newX = this.getX() + vec3.x; double newY = this.getY() + vec3.y; double newZ = this.getZ() + vec3.z; this.setDeltaMovement(vec3); // this.updateRotation(); // no need because projectile rotation is already initialized in Projectile::shoot! this.setPos(newX, newY, newZ); } // other methods ... } You can also see that I created this custom entity with GeckoLib. Other than the code above, is there anything I need to change in the Renderer class? public class CustomProjectileRenderer extends GeoEntityRenderer<CustomProjectileEntity> { public CustomProjectileRenderer(EntityRendererProvider.Context renderManager) { super(renderManager, new CustomProjectileModel()); this.shadowRadius = 0.0f; } public @NotNull ResourceLocation getTextureLocation(@NotNull CustomProjectileEntity instance) { return new ResourceLocation(ExampleMod.MODID, "textures/entity/custom_projectile_texture.png"); } // SOLUTION: override GeoEntityRenderer::actuallyRender @Override public void actuallyRender(PoseStack poseStack, CustomProjectileEntity animatable, BakedGeoModel model, RenderType renderType, MultiBufferSource bufferSource, VertexConsumer buffer, boolean isReRender, float partialTick, int packedLight, int packedOverlay, float red, float green, float blue, float alpha) { poseStack.mulPose(Axis.YP.rotationDegrees(animatable.getYRot())); poseStack.mulPose(Axis.XP.rotationDegrees(-animatable.getXRot())); super.actuallyRender(poseStack, animatable, model, renderType, bufferSource, buffer, isReRender, partialTick, packedLight, packedOverlay, red, green, blue, alpha); } } Edited March 11, 20232 yr by LeeCrafts
March 11, 20232 yr Author Solved. I just had to override GeoEntityRenderer::actuallyRender and apply the rotations there. Super.actuallyRender has to be called afterwards (not before). I think that the reason why I had to do this manually is because my CustomProjectileEntity is not a LivingEntity. I looked at the code in the GeoEntityRenderer class, and its rendering methods apply rotations to entity that are LivingEntities. Kinda explains why the custom mob I had also created with GeckoLib had no issue rotating. And there's no need to call updateRotation() because the projectile's rotation is already initialized in Projectile::shoot. Edited March 11, 20232 yr by LeeCrafts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.