enter image description here

Above image is for ref to better representation.

I have box2d object and i know start point & end point position.

Now i want to give any force or impulse such that b2body will first collide at end point BUT with different speed also should collide at that same end point.

How should i achieve this?

  • \$\begingroup\$ You should write the physics equation of your object and solve them. I guess it is something you do in class around 11th grade? \$\endgroup\$ – realUser404 Jan 10 '17 at 10:19
  • \$\begingroup\$ @realUser404 Kinematic equations aren't thaught until 11th, yeah, but you should be able to do them after 10th \$\endgroup\$ – Bálint Jan 10 '17 at 10:43

Let's say you have a gravity force g (m/s²). The horizontal speed doesn't change, so you first need to calculate the amount of time it reaches the target horizontally:

t = distanceX / speedX

The object need tk reach the target in the same time vertically too. We will have a speed of vY (m/s) at start and vY - g * t (m/s) at the end vertically (positive speed goes upwards). The average vertical speed is

vAvg = (vY + vY - g * t) / 2 = vY - g * t / 2

This average speed needs to be so big, that the object would reach the target position in time t if there's no gravity

vY - g * t / 2 = distY / t

You should be able to get the starting upwards velocity by adding g * t / 2 to distY / t

So, together, to get the vertical speed vY, you need to do:

t = distX / vX
vY = distY / t + g * t / 2
  • \$\begingroup\$ Keep in mind, box2d is not deterministic. You'll get some pretty accurate behavior using these equations, but it will never be exactly repeatable or exactly the same on different devices. \$\endgroup\$ – NauticalMile Jun 30 '17 at 21:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.