Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

unity predicts rigidbody position in x seconds

Vector3 predictRigidBodyPosInTime(Rigidbody sourceRigidbody, float timeInSec)
{
    //Get current Position
    Vector3 defaultPos = sourceRigidbody.position;

    Debug.Log("Predicting Future Pos from::: x " + defaultPos.x + " y:"
        + defaultPos.y + " z:" + defaultPos.z);

    //Simulate where it will be in x seconds
    while (timeInSec >= Time.fixedDeltaTime)
    {
        timeInSec -= Time.fixedDeltaTime;
        Physics.Simulate(Time.fixedDeltaTime);
    }

    //Get future position
    Vector3 futurePos = sourceRigidbody.position;

    Debug.Log("DONE Predicting Future Pos::: x " + futurePos.x + " y:"
        + futurePos.y + " z:" + futurePos.z);

    //Re-enable Physics AutoSimulation and Reset position
    Physics.autoSimulation = true;
    sourceRigidbody.velocity = Vector3.zero;
    sourceRigidbody.useGravity = false;
    sourceRigidbody.position = defaultPos;

    return futurePos;
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: visual studio import excel get document created date 
Csharp :: static {} 
Csharp :: c# check number is odd or even 
Csharp :: unity recttransform set anchor 
Csharp :: how to get connection string from xml file in c# 
Csharp :: add numbers c# 
Csharp :: c# bitwise or 
Csharp :: c# stack 
Csharp :: Acrylic UWP Title bar C# 
Csharp :: c# xamarin forms use AssetManager to get text file 
Csharp :: how to get the size of an array in c# 
Csharp :: C# listview as listbox 
Csharp :: randon C# 
Csharp :: c# mapper.map 
Csharp :: unity overlapcircle 
Csharp :: deserialize list of objects c# 
Csharp :: C# get the last item of the array 
Csharp :: c# resize image from byte array 
Csharp :: Load Level Action for unity 
Csharp :: vbnet programatically convert type to db type 
Csharp :: git change remote origin 
Html :: starter data jpa maven dependency 
Html :: regex find html comment 
Html :: centralize div bootstrap 
Html :: jquery $ is not defined 
Html :: html dot symbol 
Html :: lorem ipsum 
Html :: how to link to an email in html 
Html :: justify-content-between bootstrap 4 
Html :: how to create a page break html 
ADD CONTENT
Topic
Content
Source link
Name
8+7 =