Question

I have been fiddling with MathHelp.Lerp(); trying to find the easiest way to rotate the direction the missile is traveling. Right now it will instantly go the direction the player/mouse is located.

Would Larp be the best to use or would some other type of direction rotation be what I should be after? Latest post, example of what I mean.

    protected override void Update(GameTime gameTime)
    {
        // Allows the game to exit
        if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            this.Exit();

        delta = (float)gameTime.ElapsedGameTime.TotalSeconds * Speed;

        direction = mousePosition - missilePosition;
        direction.Normalize();

        missilePosition += direction * delta;

        //missilePosition = Vector2.Lerp(missilePosition, mousePosition, 2.0f);

        mouse = Mouse.GetState();

        mousePosition = new Vector2(mouse.X, mouse.Y);

        base.Update(gameTime);
    }

Having the image rotate with the direction of the missile is also something that I have been looking up and trying to figure out. How would I have the image rotate as the direction rotates?

Was it helpful?

Solution

If you use velocity to move your missile, you can use this code (maybe you will need to normalize it). writing from head.

rotation = -(float)Math.Atan2(velocity.Y, velocity.X);

so if your velocity is (1,0) meaning your misslile is going straight from left to right. Atan2(1,0) will give you 1.57 radiants (90 degrees). to make this working, your texture of missile must be faced up. and this code will turn it to 90 degrees, to the right.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top