Saturday, August 24, 2019

xna - Farseer: How can I calculate the needed velocity in this case?


I have two platforms and one ball. The ball should fly from the red platform to the blue platform. The ball should land somewhere in the purple rectangle of the blue platform.



How can I know how fast the linear velocity of the ball should be to accomplish the jump of the ball? Is there a mathematical formula to calculate the linear velocity(x,y) which should be added to the ball so that the ball can jump to the blue platform?


The ball should always land in the purple area.


Distance(width) from the ball to the target: 212 pixel


Distance(height) from the ball to the target: 52 pixel


The distances were measured from the center of the ball to the center of the purple rectangle.


The gravitation of my world is world(0,3).



Upadte I use the following formula for the impulse:



impulse = Vector2(distance.x / time * mass + gravity.x / 2 * time * mass, distance.y / time * mass + gravity.y / 2 * time * mass);



mass: mass of the ball


It's working with this formula, but only if the value of the time is not too low. time = 2.0f(or higher) is working but if I use time = 1.0f, then the ball is touching the left side of the blue platform.


Why is the formula not working with low time values? I don't understand that.



Answer



Short answer:


impulse = (gravity * time*time + distance * 2.0) / (time * 2.0);


(or optimized for the specific numbers you asked for)


impulse = Vector2(212.0/time, 52.0/time + 1.5*time);

(although, I think maybe you wanted this one that accounts for gravity but can be used to calculate any possible jump)


impulse = Vector2(distance.x/time, distance.y/time + 1.5*time);



Long answer: (pre-calculus required)


First express your problem mathematically:




Integrate to find that:



Solving this for impulse yields:



Which is our answer, notice that time is still unknown in this system. This means there are infinite trajectories that will land on the purple rectangle. You have to decide how long it should take.


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...