- Home /
How to calculate how much Force (ForceMode.Inpulse) to apply to reach a specific target transform in 3D space?
Hello!
I need to calculate how much Force to apply (ForceMode.Impulse) to a Rigidbody so that it will reach a target transform in 3D space.
Currently, what I do is calculate the direction from the object to the target transform:
// Get the direction towards the target
Vector3 direction = target.position - playerRB.position;
Then I add some upwards direction because I want for it to arc like it's a ball (well it IS a ball) launched in the air, as I don't want for the object to go to a straight line:
// Normalize the Direction vector
direction.Normalize();
// Add some UP movement
direction = direction + Vector3.up;
And finally, I try to calculate how much force to apply accounting for the Distance between the two objects, but here it's mostly guesswork and it doesn't really work often (I save this calculated value in a float called forceToBeApplied).
Afterwards I launch the object:
// Add force to the ball (Launch)
playerRB.AddForce(direction * forceToBeApplied, ForceMode.Impulse);
Alas, as I mentioned, the forceToBeApplied float is hacky and the results are not always the intended ones.
How can I calculate that float so that the rigidbody reaches the intended target? I assume we need to consider the world gravity, the rigidbody drag and the angularDrag.
Any help will be appreciated :-)
Thanks!
Your answer
Follow this Question
Related Questions
Can't adding Force to move ball Left or Right 0 Answers
How do you create a continuous physics simulation in Unity? 1 Answer
Setting a RigidBody's velocity messes with my custom gravity, not sure how to proceed. 0 Answers
Applying force to another object by hitting it with an animated object: Possible? 1 Answer
Force required to throw an object. 1 Answer