Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unity: AddTorque doesn't work

Tags:

unity3d

I have some obstacle like stick that is upright. It's move by velocity vector in rigibody2d (-4,0). And I have a hero which always stay in center of game screen. When hero collides with a stick, I want that obstacle flew away with some rotation, depending on the point of collision (like the laws of physics, if the collision point near the edges, then more torque).

But, AddTorque on rigibody2D doesn't work, although AddForce works fine.

There is code of collision

void OnCollisionEnter2D(Collision2D other)
{ 
    if (other.collider.tag == "Block")
    {
        if (InvBonusEnabled) {
            other.collider.isTrigger = true;
            other.rigidbody.isKinematic = false;
            other.rigidbody.AddTorque(100); //simple test doesn't work
            other.rigidbody.AddForce(new Vector2(200, 50));
           //  
        }
    }
}

I can't attach screen with prefab rigibody2D and collider2D settings (reputation 10 required on this stackoverflow)

Rigibody2D

Mass: 1

Linear Drag: 0

Angular Drag: 0.05

Gravity Scale: 1

IsKinematic: True

All Freeze Postion and Rotation are false

Collider2D

IsTrigger: false

What am I doing wrong?

like image 574
Ilja Bulatov Avatar asked Oct 31 '22 20:10

Ilja Bulatov


1 Answers

Your torque may be too low of a number. Try upping it to the thousands or higher even.

Try also increasing the rigidbody.maxAngularVelocity thats worked for me before

like image 149
maksymiuk Avatar answered Nov 23 '22 00:11

maksymiuk