- Home /
Adding a force to an object relative to a rotation?
Currently I'm pushing this ladder over by adding a force on the Z-axis using an accelerometer, and it's working just fine.
rigidbody.AddForce (0.0f, 0.0f, [accelerometer z-axis]);
I'd like to have the camera rotate however, whilst still having the accelerometer push the object in the correct direction relative to the camera's rotation.
At the moment I've added the cube above the ladder and attached it to the ladder using a hinge joint so that the cube can rotate on the Y-axis. That way the cube can rotate according to the accelerometer lean direction, and the force can be applied to it's Z-axis.
I figured this would push the ladder relevant to the lean direction, but nothing seems to happen. I tried giving the cube zero gravity & breaking the hinged joint in Play Mode to test for the issue, and the force is only being applied to the world's Z-axis rather than the cube's local. I tried AddRelativeForce too, and that seems to push the cube along it's own Z-Axis at the time of the hinge breaking - the Z-axis/rotation doesn't appear to update itself after breaking the joint.
Any advice on how to get this to work would be greatly appreciated - alternate solutions are great too.
Thanks for your time.