1
\$\begingroup\$

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?

\$\endgroup\$
2
  • \$\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\$ Commented Jan 10, 2017 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
    Commented Jan 10, 2017 at 10:43

1 Answer 1

1
\$\begingroup\$

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
\$\endgroup\$
1
  • \$\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\$ Commented Jun 30, 2017 at 21:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .