- Home /
Projectile Trajectory Velocity, with predefined Start and End Positions
Guys and Gals,
I am in serious need of help.
I cannot for the life of me get this to work properly.
If I have:
public Vector2 GetInitialVelocity(Vector2 A, Vector2 B, float MaxJumpForce, float Gravity)
{
float distanceToEnd = Vector2.Distance(A.position, new Vector2(B.x, A.y));
float TimeStartToPeak = MaxJumpForce / Mathf.Pow(Gravity, 2);
float TotalTimeInTheAir = TimeStartToPeak * 2;
float XVelForJump = distanceToEnd / TotalTimeInTheAir;
return new Vector2(XVelForJump, MaxJumpForce);
}
It works, if both start and end have the same Y value.
How can I get it to give me the velocity I need to move from A to B, regardless of height?
It won't be something that's updating every frame. I just want to be able to pass the velocity to the rigidbody, and not have to do anything until it hits something again. I'm not handling air resistance or anything.
Any ideas?
I've seen multitudes of math equations and formulas, etc.
But I have genuinely no idea how to convert half the symbols into script, as I don't know what they mean.
They all seem to want the input of a time variable, when I don't care how long it takes.
Thanks in advance everyone.
I'm assuming I'm missing something simple.
Peace
Your answer
Follow this Question
Related Questions
Shoot Projectile on the direction of where the gun is facing 1 Answer
Increase velocity without changing trajectory 1 Answer
2D rigidbody velocity relative to rotation? 0 Answers
how to make an 2d object move the direction its facing using rigidbody2d.velcoity 1 Answer
Adding force relative to rotation 1 Answer