Jump to content

Rotate Projectile?


ulfgur

Recommended Posts

Hi,

  I'm working in 1.8.

 

  I have successfully made several projectile weapons, all of which used bullets. Now I'm working on throwing knives, and want my projectile rotated like an arrow, so that it starts (and continues) facing away from the player, instead of being parallel to the camera angle.

 

    How do I accomplish this?

 

I'm not sure what code is relevant yet, if any, so sorry if I'm spraying irrelevant code all over the place.

 

Here's my renderer:

 

public void doRender(Entity entity, double x, double y, double z, float p_76986_8_, float partialTicks)

    {

        GlStateManager.pushMatrix();

        GlStateManager.translate((float)x, (float)y, (float)z);

        GlStateManager.enableRescaleNormal();

        GlStateManager.scale(0.5F, 0.5F, 0.5F);

     

        //I tried changing this a couple different ways, but nothing happened. It's

        //possible that if this is the method I'm looking for, I just don't know how

        //use it.

        GlStateManager.rotate(-this.renderManager.playerViewY, 0.0F, 1.0F, 0.0F);

        GlStateManager.rotate(this.renderManager.playerViewX, 1.0F, 0.0F, 0.0F);

        this.bindTexture(modelResourceLocation);

        this.renderitem.renderItemModel(this.convertEntitytoStack(entity));

        GlStateManager.disableRescaleNormal();

        GlStateManager.popMatrix();

        super.doRender(entity, x, y, z, p_76986_8_, partialTicks);

    }

 

 

 

And here's the constructor for the entity.

 

public class EntityThrowingKnife extends EntityThrowable

{

public static final float speed = 1;

public static final float inacurracy = .35f;

 

 

    public EntityThrowingKnife(World world)

    {

        super(world);

        this.motionX += calcinaccuracy();

        this.motionY += calcinaccuracy();

        this.motionZ += calcinaccuracy();

        this.motionX *= speed;

        this.motionY *= speed;

        this.motionZ *= speed;

    }

    public EntityThrowingKnife(World world, EntityLivingBase par2EntityLivingBase)

    {

        super(world, par2EntityLivingBase);

        this.motionX += calcinaccuracy();

        this.motionY += calcinaccuracy();

        this.motionZ += calcinaccuracy();

        this.motionX *= speed;

        this.motionY *= speed;

        this.motionZ *= speed;

    }

   

    public float calcinaccuracy()

    {

    return (rand.nextFloat() * inacurracy) - (.5f * inacurracy);

    }

 

//.....

 

 

 

 

 

 

 

Thanks!

 

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.