How to know the velocity of a NewtonBody in Unity ?

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

How to know the velocity of a NewtonBody in Unity ?

Postby blackbird_dream » Tue Nov 21, 2017 11:24 am

Newton in Unity is really great. Much faster/easier to handle than in raw C++ or Delphi progs.
My question is now : how can I get the velocity of a Newtonbody ?
something like GetComponent<Rigidbody>().velocity for a physxx rigidbody.
thks
User avatar
blackbird_dream
 
Posts: 354
Joined: Wed Jun 07, 2006 3:08 pm
Location: France

Re: How to know the velocity of a NewtonBody in Unity ?

Postby Sweenie » Tue Nov 21, 2017 2:27 pm

I've added a Velocity and Omega property to NewtonBody.

By the way, if you are calling GetComponent<Rigidbody>().velocity inside the update function I recommend storing the component reference in the Start function instead.
It will be more efficient than calling GetComponent every frame.

Like this...

Code: Select all

public class MyTestScript : MonoBehaviour
{

    NewtonBody body = null;

    // Use this for initialization
    void Start ()
    {
        body = GetComponent<NewtonBody>();
    }
   
   // Update is called once per frame
   void Update ()
    {
        if (body)
        {
           Vector3 vel = body.Velocity;
        }   
    }
}

Sweenie
 
Posts: 498
Joined: Mon Jan 24, 2005 7:59 am
Location: Sweden

Re: How to know the velocity of a NewtonBody in Unity ?

Postby blackbird_dream » Tue Nov 21, 2017 2:30 pm

Thks so much Sweenie.
I'll test it tomorrow morning.
User avatar
blackbird_dream
 
Posts: 354
Joined: Wed Jun 07, 2006 3:08 pm
Location: France

Re: How to know the velocity of a NewtonBody in Unity ?

Postby blackbird_dream » Wed Nov 22, 2017 5:35 am

Thks again.
I declared my script as a subclass of NewtonBodyScript
So I didn't need to declare
Code: Select all
    NewtonBody body = null;

Is it a problem regarding my previous question about sharing dll instead of sources ? I mean the script declaration
User avatar
blackbird_dream
 
Posts: 354
Joined: Wed Jun 07, 2006 3:08 pm
Location: France


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 20 guests

cron