XNA curve sprite animation in XNA

I would like to implement a ballistic trajectory in the XNA game and tried to find a better way to get the projectile to follow the gravitational curve.

The best I can think of is to simply compute the curve first and save it in the Curve class. Then make the sprite move along this curve.

But I can’t figure out how to actually move the sprite along this curve.

How can I do this, or just the best way?

+3
source share
1 answer

Basically you want to use high school level physics of the equation of motion (Wikipedia article).

For projectile movement, this is an important equation:

s = s₀ + v₀t + ½at²

( : , , , ).

, , 2D. . X , .

Y , - .

, , .

XNA - , :

Vector2 initialPosition = Vector2.Zero;
Vector2 initialVelocity = new Vector2(10, 10); // Choose values that work for you
Vector2 acceleration = new Vector2(0, -9.8f);

float time = 0;
Vector2 position = Vector2.Zero; // Use this when drawing your sprite

public override void Update(GameTime gameTime)
{
    time += (float)gameTime.ElapsedGameTime.TotalSeconds;

    position = initialPosition + initialVelocity * time
               + 0.5f * acceleration * time * time;
}

, , , .

+9

Source: https://habr.com/ru/post/1755143/


All Articles