-3

Ok so I have read this question Calculating trajectory. And it is sort of working in my program. I am trying to produce nice parabolic arcs with this. Like so .. enter image description here

The results I am getting look more like this.. enter image description here

Here is my the code that gets updates every frame. Note: my object is starting on the right side of the screen and moving towards the left which is what I want.

public void update(float deltaTime)
{
    this.mDeltaTime = deltaTime;
    ....

    mPosition = new Vector2(mPosition.X + .5f * (mDeltaTime - 5.35f)*.25f, 
    mPosition.Y + .5f * (mDeltaTime + 5.35f)*.25f);

    ....
}

I am going to go back and clean it up once its producing what I need it to. I am not sure if the initial starting position is the apex of the arc or if it is just moving linearly.

chewpoclypse
  • 135
  • 6
  • 4
    What's your question? If you read the other question, it should be obvious that you haven't implemented the equation in the answer to the other question. You're only updating the position with a mostly constant value, you're not tracking velocity or updating it. – House Jul 14 '16 at 22:34
  • Can this be done using the Vector2 methods? If so what would it sorta look like? – chewpoclypse Jul 15 '16 at 03:07

2 Answers2

1

Parameterized equations of (2D) motion for a parabola are as follows:

x = x0 + t * Vx
y = y0 + t * Vy - 0.5 * g * t^2

with a sign convention of increasing X rightward, increasing Y upward.

These are a simple adaptation of the kinematic equations of motion under constant acceleration.

Pieter Geerkens
  • 2,111
  • 12
  • 17
-1

The accepted answer can be found at Animate Sprite Along a Curve path in XNA

I appreciate the help people have tried to post.

static float mFlightTime = 0.0f;

Vector2 mVelocity = new Vector2(-12, -8);
Vector2 mAcceleration = new Vector2(0f, 1f);
Vector2 mStartingPosition =  new Vector2(260.0f, 31.0f);

Vector2 mPosition = Vector2.Zero;

public void update(float deltaTime)
{
    this.mDeltaTime = deltaTime;
    ....

    mFlightTime += .3f;

    mPosition = mStartingPosition + mVelocity * mFlightTime +
                            0.5f * mAcceleration * mFlightTime * mFlightTime;
    ....
}
chewpoclypse
  • 135
  • 6