Problem with getting rigidbody.angularVelocity

Hi there,

I’m working with a rigidbody and need to use its angular velocity. But when using a MoveRotation method on it, its angularVelocity property always stays at zero. However, if I set rigidbody.isKinematic to true, angularVelocity begins to calculate correctly…

I wonder if that’s as it have to be, and if so, how can I calculate angularVelocity by myself with not kinematic rigidbodies?

Here is my script, which I use with a rigidbody:

using UnityEngine;
using System.Collections;

public class C_PlayerController : MonoBehaviour {

    private Rigidbody myRigid;
    private Vector3 cursorPosition;
    private Quaternion targetRotation;

    void Awake () {
        myRigid = GetComponent<Rigidbody>();
    }

    void Update () {
       cursorPosition = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, C_CameraController.currentDistance));
       cursorPosition.y = 5;
       targetRotation = Quaternion.Slerp(myRigid.rotation, Quaternion.LookRotation(cursorPosition - myRigid.position), Time.deltaTime * 2);
    }

    void FixedUpdate () {
       myRigid.MoveRotation(targetRotation);
       myRigid.AddForce(-myRigid.transform.forward * Vector3.Distance(myRigid.position, cursorPosition), ForceMode.Acceleration);

       print(myRigid.angularVelocity);
    }

}

What I’m trying to do there is making the rigidbody to “look” at the mouse cursor and follow it, while checking its angularVelocity (which stays at zero, if isKinematic is false).

I’m really confused with that problem. Would appreciate any help. Thanks!

1 Like

Hi Elringus,

To be honest you are probably posting your question in the wrong place. Ask the question over at Unity Answers and your question will get some great answers :wink:

Actually I did, but with no luck so far =/
I also googled that problem a lot, but again without any results…

1 Like

Sorry Elringus. It’s normally pretty good over there. Have you tried bumping it?

umm, not really… I just thought, that meaningless bump replies would make moderators to ban me or something like that ^^ So, is it ok to just reply “bump” there?)

1 Like

Answers is pretty much maintained by long time users. The main things they frown upon is incorrect use of the answers / comments fields, not marking a question as answered if it gets solved, and asking how to make a MMORPG :wink:

If it has been up for a day or so, then a little bump should be OK.

Ohh, I see. Ok then, I’ll try to bump it a little. Thanks for the advice :slight_smile:

1 Like