- Home /
Angular velocity not affecting Rigidbody2D
I have a simple Rigidbody2d which is linked to the parent of a humanoid character in a side-view. The goal is to have the character jump and do a backflip by applying torque to the rigidbody. This character is animated which I know could prevent the object from rotating when it has angular velocity but animations only affect the children of the object. None of these children have rigidbodies. I set the angular velocity directly in a script to give the object a sudden burst of rotation. After that I use AddTorque with a ForceMode2D.Force to mantain a rotation speed since the angular drag of the rigidbody is set to 2. Here is a screenshot of the setup : The second animation event triggers a method which sets the angular velocity. Here is the code of this method : public void ApplyImpulseRot(){ if (goodJump) { rb.angularVelocity = rotationImpulse; Debug.Log(rb.constraints + " " + rb.angularVelocity); goodJump = false; } }
I added the Debug.Log to verify that the rigidbody has no constraints when applying the angular velocity and that the velocity is correctly applied. When playing, this debug logs "None 60" which shows that the problem is not linked to either of these possible issues. I have a second Debug.Log in the FixedUpdate that logs the angular velocity at every physics calculation and this shows me the expected behaviour of the angular velocity during the player's jump (the velocity starts at 60 and then increases until the player returns to a grounded state at which point the velocity is set to 0 because the rigidbody becomes constrained for the z rotation). When I check the object with the rigidbody's rotation it stays fixed for the whole jump. No changes to the rotation at all. Another wierd thing is that when increasing the burst of angular velocity to a very high value (from 60 to 10000 for example) the object still doesn't rotate but shoots up in the air. Here is a screenshot of a frame during the jump where the console shows the angular velocity and where we can also see the rigidbodies rotation which by default is 0 :
I really can't understand why the object is not rotating. Your help is much appreciated.
Update : the problem is due to the animation. I have tried running the game jumping and waiting for the velocity to be applied by the animation event. After that I pause the game turn off the animator and only then does the object start rotation. The weird thing is that the rotation of the Runner gameobject is not a paramater of the animations running during the jump. I still need help to understand why the animator is preventing the rotation of the object.
Answer by RER1200 · May 20, 2020 at 11:25 AM
I've now fixed the issue. By removing the property concerning the rotation of the Runner gameobject in all animations of the animator, the object now rotates according to its rigidbody's angular velocity. I still don't understand why a parameter of an animation not running at the time affects all other animations of the object. I'm not sure if this is a bug or a hidden consequence of the way the animator works but the easy fix is to remove the parameter from all animations and control the rotation using a script.
Your answer
Follow this Question
Related Questions
Torque stopped working after update 1 Answer
How to rotate a Rigidbody2D faster than 4500 (degrees/s)? 0 Answers
rigidbody2D.AddTorque() works differently on iOS, in editor and in web player 1 Answer
After AddTorque, the resulting angularVelocity depends of the RigidBody's velocity? 0 Answers
How to disable collisions without disabling rigidbody? 1 Answer