- Home /
AddForceAtPosition Creating Torque When It Shouldn't
So I've got a player spaceship, with child thruster objects. I want to use AddForceAtPosition to simulate the effects of firing said thrusters. To test the setup, I've got only a single thruster, and for the time being, I'm applying the force at the origin of the player ship, to verify that AddForceAtPosition is working like I want it to. I am under the impression that AddForceAtPosition should act exactly like AddForce if it's applied at the object's origin. However, when I test this setup, it give the ship torque as well.
The following method is in the PlayerController script, attached to the parent spaceship. It's passed a reference to the thruster to be fired. It's only called from FixedUpdate.
private void fireThruster(GameObject thruster, float throttle)
{
thrust = thruster.GetComponent<ThrusterController>().thrust;
Vector3 direction = transform.TransformDirection(thruster.transform.rotation * transform.forward);
rb.AddForceAtPosition(direction * throttle * thrust, transform.TransformPoint(transform.position));
}
I've verified that the direction is what I expect by drawing a ray. I'm currently using the parent ship's position as the location of the force. Later it will be the location of the thruster instead.
I also transform the position and rotation to world coordinates before passing them to AddForceAtPosition, as the docs say it takes world values.
When the thruster fires, the ship moves forward as expected, but also pitches nose-down.
Is the center of mass not at the object's origin? Am I missing something else dumb? Does AddForceAtPosition just not work like I think it does?
Your answer
Follow this Question
Related Questions
Gimbal Lock like behavior using AddForceAtPosition in child objects 0 Answers
Unity 2019.3.0f6 - Trouble with physics, cubes turn left after some meters 1 Answer
Add force on objects from a specific location in space 2 Answers
Character Controller Pushes Car With Wheel Colliders? 0 Answers
Pinwheel prevents player by moving 0 Answers