Unity3D rotates the inertia of an object

Source: Internet
Author: User

When it comes to inertia rotation, I think of wheel Collider, which simulates the rotation of cars, including wheels. What I want is the first speed of an object, when an object is blocked by a variety of forces, the rotation speed of our object will get smaller and smaller, and finally it will be static.
If you want to add the rigidbody to an object, I will use the method of the rigidbody AddTorque function. Do not use AddRelativeTorque because it is local. You will know it if you try it; these two functions are used in FixedUpdate. First, let's take a look at the effect of the AddTorque function. You will find that the direction of the torque is determined by the right hand and the orientation of the object is vertical. The thumb indicates the direction of the torque, and the four fingers indicate the direction of the rotation. On the mobile phone, two directions are rotated, respectively, around the Y axis and the X axis, so the Z axis is 0, regardless of him. Similarly, we still use Input. getAxis ("Mouse X/Y") function, you will use their size to indicate the direction of the rotation, also according to the right hand determine the direction of the torque, then, add some resistance to the Drag and Angular Drag of the Rigidbody. Do not add too much. It cannot be rotated.

[Java]
Var h: float;
Var v: float;
Var Torque: Vector3;
Function FixedUpdate (){
Rigidbody. AddTorque (Torque * 1 );
}
Function Update (){

If (Input. GetTouch (0). phase = TouchPhase. Moved ){
H = Input. GetAxis ("Mouse X"); // positive and left negative
V = Input. GetAxis ("Mouse Y"); // top, bottom, and bottom
}
Else {
H = 0;
V = 0;
}
Torque = Vector3 (v,-h, 0 );

If (Input. GetKey (KeyCode. Escape )){
Application. Quit ();
}
}


From dlnuchunge's column

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.