Hi, I’ve been playing around a bit with the rigidbody.AddForceAtPosition() function and I was unable to really tell how it works. The thing I’m struggling with is the result torque, can any one tell me what’s the math behind it?
For example, I was trying to apply a vertical force in the upwards face of a rectangular 3d box when pushing the space key:
// This function is called every fixed framerate frame, if the MonoBehaviour is enabled
private void FixedUpdate()
{
float impulse = CrossPlatformInputManager.GetAxis("Jump");
Move(impulse);
}
private void Move(float impulse)
{
float forcemultiplier = 4.0f;
Vector3 pointofimpulse = (Vector3.Scale(rigidbody.GetComponent<Collider>().bounds.extents, Vector3.up));
Vector3 force = transform.up * forcemultiplier * impulse;
Debug.Log("Point of impulse = " + pointofimpulse);
//lets draw a visual cue of the direction of the force:
Debug.DrawRay(rigidbody.position, pointofimpulse * forcemultiplier, new Color32(255, 128, 16, 255));
rigidbody.AddForceAtPosition(force, pointofimpulse, ForceMode.Force);
}
The results seemed to be that the box will jump towards the side the local X axis (red axis) is pointing to, if its pointing to the ground or sky it would move back and forth some degrees repeatedly when pushing space.
But now I’ve tried with the box 90 degrees rotated in the Y axis, and its jumping towards the Z local axis instead of X.