I'm faced with the following problem:
I'm trying to implement a rigidbody-based movement for my submarine game which means I want (need?) to useAddForce()
and AddTorque()
in order to get proper collision detection.
Currently I'm achieving the desired rotational behavior by quaternion multiplication/rotation.
But with this approach, the submarine bugs through the terrain. To avoid that it seems my only option is to use a rigidbody.
Here's a video illustrating the problem.
On the left is the correct behavior. I want to keep the nose pointing where it has been tilted at and not rotate around a fixed axis, Vector3.up
in this case.
How can I calculate the correct input for AddTorque(vec3)
to get the result I need?
Left attempt with quaternions (what I need):
input2 = Input.GetAxis("Sideways");
transform.rotation =
Quaternion.Euler(0, input2 * Time.deltaTime * rotation_speed, 0) * transform.rotation;
Right attempt with torque (which doesn't quite work yet):
// in Update()
rotateY = Input.GetAxis("Sideways");
void FixedUpdate() {
// experimenting with AddTorque() and various inputs didn't
// get me any further
rb.AddRelativeTorque(Vector3.up * rotateY * speed);
}
I hope someone can point me in the right direction, thanks in advance.
AddRelativeTorque
uses the coordinate system of the body, so up means up relative to the body. What happens we you useAddTorque
instead, with exactly the same arguments? \$\endgroup\$ – monocell Oct 7 '19 at 1:21AddTorque(Vector3.up * ...
, what happens then? As far as I can see it should not change depending on the overall tilt... \$\endgroup\$ – monocell Oct 7 '19 at 8:36