- Home /
AddTorque() doesn't work when also using AddForce()
Here's my code:
function FixedUpdate () {
moveTimer -= Time.deltaTime;
if(moveTimer < 0.0f) finished = true;
if(!finished) {
UpdateForce();
UpdateTurning();
}
}
function UpdateTurning() {
var horz:float = Input.GetAxis("Left Thumbstick Horizontal");
rigidbody.AddTorque(Vector3.up * horz * ROTATE_SPEED * speedMultiplier, ForceMode.Impulse);
}
function UpdateForce() {
var direction:Vector3 = transform.forward;
rigidbody.AddForce(direction * speed * speedMultiplier, ForceMode.Acceleration);
}
I'm using this code to move an object forward automatically, and have the user steer it.
The issue is that when I'm calling AddForce() and AddTorque(), the object barely rotates (a small, negligible amount).
What I've tried:
1) Only calling AddTorque(), and not AddForce(), works perfectly fine for rotating the object.
2) Calling AddRelativeForce() instead of AddForce() makes it go backward and the rotation is all sporadic.
3) When calling AddRelativeTorque(), there's no noticeable difference.
4) Changing the ForceMode on either call doesn't cause and noticeable difference.
Some notes: The rigidbody is not kinematic, and has drag and angular drag.
I've been working on this issue for several hours, so any help would be much appreciated! Thanks!
Is the object rolling/sliding on a surface, or through space (not sure how dynamic friction affects rotation.)
Have you looked at values for horz
? I don't know what a thumbstick is, or how you set forward speed, but it might be that horz
just happens to be smaller, in the "forward and turn" stick position.
Then, just for fun, what happens if you crank up the rotate speed, like x30? In other words, can it simply not turn well while moving, or does it suddenly just need higher values?
It's flying through space, so there's no friction being applied. Just drag.
The values for horz are okay. While testing, I made sure to only go left and right on the thumbstick, and this worked perfectly when AddForce() wasn't being applied.
Cranking the rotate speed, by the hundreds and thousands had no effect. I did find that there's a maximum angular velocity in the project settings which was super low, like 6. I had to crank that up to 200 to get a decent effect.
It seems that more torque/angular velocity is required to turn the object that's moving that when at rest. Is this a property in real physics?
Answer by partyjohn · Feb 20, 2015 at 01:44 AM
Increasing the maximum angular velocity in the project's physics settings made it work, but it has some side effects.
I had to crank it from 6 to 200 to get the control I wanted, and it seems to increase the force of any collisions when the object is turning into it, like, scary increase! objects flying around at crazy speeds cause it casually turned into a wall.
The ship has the 'bouncy' physics material, but he amount of bounce I'm getting is ridiculous, specifically when rotating into the collision.
It seems that more torque/angular velocity is required to turn the object that's moving that when at rest. Is this a property in real physics?
Do I just need to find some kind of sweet spot with the maximum angular velocity, and the objects mass/force being applied to it?
Any idea what's causing the crazy collisions?
I realize this was over 3 years ago... But I'm having the same issue with the crazy bouncing due to a spin on the object. Did you every find a solution?