Homing Missiles, How Do They Work?

后端 未结 1 1653
余生分开走
余生分开走 2021-01-29 08:26

What I am trying to create

  • An object that will launch a missile towards the player, if it collides with player, player dies.

相关标签:
1条回答
  • 2021-01-29 08:38

    You can get the distance from one point to another, and turn that into a direction to go to.

    //Find the delta time
    float delta = (float)gameTime.ElapsedGameTime.TotalSeconds * 60;
    //Find the direction
    Vector2 direction = mousePosition - misslePosition;
    direction.Normalize();
    //Move towards it
    currentPos += direction * delta;
    

    It needs to be multiplied by the elapsed time so it appears the same no matter what FPS you are running at.

    You may need to adjust for speed, but it should create a pattern like this:

    http://i.imgur.com/D8FTFFt.png

    If you would like the missle to slowly turn towards the target, you can experiment with MathHelper.Lerp to slowly change the angle.

    0 讨论(0)
提交回复
热议问题