Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

how to keep rigidbody2D upright unity

Rigidbody hoverRB; // hovercraft's rigidbody

...

void FixedUpdate() 
{    
    Quaternion deltaQuat = Quaternion.FromToRotation(hoverRB.transform.up, Vector3.up);

    Vector3 axis;
    float angle
    deltaQuat.ToAngleAxis(out angle, out axis);

    float dampenFactor = 0.8f; // this value requires tuning
    hoverRB.AddTorque(-hoverRB.angularVelocity * dampenFactor, ForceMode.Acceleration);

    float adjustFactor = 0.5f; // this value requires tuning
    hoverRB.AddTorque(axis.normalized * angle * adjustFactor, ForceMode.Acceleration);
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: set the page that FormsAuthentication.RedirectFromLoginPage redirects to 
Csharp :: c# loop through datatable and update 
Csharp :: declare string array c# without size 
Csharp :: c# entity framework get all records from table 
Csharp :: get ad user using email address microsoft graph C# 
Csharp :: listview imagelist c# 
Csharp :: c# loop string 
Csharp :: and operator in c# 
Csharp :: return stream from file c# 
Csharp :: unity reflect raycast 
Csharp :: where to write fluent api 
Csharp :: iframe set html content c# 
Csharp :: c# shorthand if statement without else 
Csharp :: sealed method in c# 
Csharp :: httpclient 
Csharp :: .net on vs code 
Csharp :: read all lines split C# 
Csharp :: iterate through photon player gameobjects 
Csharp :: run in new thread C# 
Csharp :: pubxml environment variables 
Csharp :: Make UI/Canvas look at Camera always. 
Csharp :: c# loop 2 time tables 
Csharp :: c# program exit 
Csharp :: how to check if a file is running in c# 
Csharp :: c# query string builder 
Csharp :: unity stop velocity movement 
Csharp :: KeyValuePair is default 
Csharp :: caesar cipher in C# 
Csharp :: c# get out of for loop 
Csharp :: vb.net drag window without titlebar 
ADD CONTENT
Topic
Content
Source link
Name
1+4 =