NewtonDynamics clumsy in Unity [SOLVED not Clumsy unlike me]

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

NewtonDynamics clumsy in Unity [SOLVED not Clumsy unlike me]

Postby blackbird_dream » Fri Mar 16, 2018 9:04 am

I made a simple test of 2 cubes falling down from 50m height, dir z.
The gravity is set to 9.8
One is updated with Newton. The second one is updated procedurally (ie theoretical position in function of time 1/2gt^2).

I ran this test with the NGDv1.5 dll in a delphi application. The 2 cubes fall down at same velocity. Their positions are close during the 50m fall.
I ran the same test in Unity. When the first cube reaches 50m the second one is half the way.

see the videos here :
https://ufile.io/y0koh
the demos here :
https://ufile.io/jpeh5
Last edited by blackbird_dream on Mon Mar 19, 2018 7:12 am, edited 1 time in total.
User avatar
blackbird_dream
 
Posts: 354
Joined: Wed Jun 07, 2006 3:08 pm
Location: France

Re: NewtonDynamics clumsy in Unity

Postby JoeJ » Sun Mar 18, 2018 4:24 am

According to the other thread, you already disabled damping. So it must be either the timestep given to Newton update or the number of calls which is wrong i guess.

Maybe you can look what's wrong there until this gets attention (i can't help with Unity plug in).
You could log realtime vs. Newtons time eventually.
User avatar
JoeJ
 
Posts: 1453
Joined: Tue Dec 21, 2010 6:18 pm

Re: NewtonDynamics clumsy in Unity

Postby blackbird_dream » Sun Mar 18, 2018 5:51 am

Thks for your reply.
It seems to be the way the plugin is hooked to Unity.
I was in touch with KooM. He asked me to test first the newton dll independently.
The v1.5 was fine and behaved perfectly as shown in my demo.
I'd like to test the last newton dll the same way. Unfortunately I can't for the moment as I do not have the last headers for delphi. KooM is about to send me a lazarus suite but It may take me some times to install it and use it for a demo.
Would you be so nice to duplicate my test with the last newton dll?
2 cubes falling down from 50m. One moved by Newton and a constant gravity of 9.8 the other one by the procedural update (0.5*g*t^2). The 2 cubes should move the same way. If so, we are sure the issue comes from the plugin itself, I mean the way Unity calls the dll (loops).

NB : in unity I minimized the timestep (60) and the number of loops (1 no effect) as well as the core number (1,2 or 3 give the same result).
User avatar
blackbird_dream
 
Posts: 354
Joined: Wed Jun 07, 2006 3:08 pm
Location: France

Re: NewtonDynamics clumsy in Unity

Postby Dave Gravel » Sun Mar 18, 2018 1:28 pm

Here a quick engine for tests.

Download:
Source Updated with 2 custom joints exemples.
https://www.mediafire.com/file/iqxvvdgp4v7wwqy/Quick_Mini_EngineV4_rev3_GL45_Newton_By_Dave_Gravel.zip

Last update little fix about debug and release dll loading.
Last update fix for compatibility with last lazarus version.

https://www.facebook.com/dave.gravel1/videos/10204469980707322/

Lazarus IDE:
https://www.lazarus-ide.org/
Last edited by Dave Gravel on Tue Mar 20, 2018 1:37 pm, edited 15 times in total.
You search a nice physics solution, if you can read this message you're at the good place :wink:
OrionX3D Projects & Demos:
https://orionx3d.sytes.net
https://www.facebook.com/dave.gravel1
https://www.youtube.com/user/EvadLevarg/videos
User avatar
Dave Gravel
 
Posts: 800
Joined: Sat Apr 01, 2006 9:31 pm
Location: Quebec in Canada.

Re: NewtonDynamics clumsy in Unity

Postby blackbird_dream » Sun Mar 18, 2018 1:51 pm

Thks Dave (aka koom).
I ll test it tomorrow at work.
User avatar
blackbird_dream
 
Posts: 354
Joined: Wed Jun 07, 2006 3:08 pm
Location: France

Re: NewtonDynamics clumsy in Unity

Postby Dave Gravel » Sun Mar 18, 2018 2:20 pm

It's a pleasure!!.
You search a nice physics solution, if you can read this message you're at the good place :wink:
OrionX3D Projects & Demos:
https://orionx3d.sytes.net
https://www.facebook.com/dave.gravel1
https://www.youtube.com/user/EvadLevarg/videos
User avatar
Dave Gravel
 
Posts: 800
Joined: Sat Apr 01, 2006 9:31 pm
Location: Quebec in Canada.

Re: NewtonDynamics clumsy in Unity

Postby Sweenie » Mon Mar 19, 2018 3:31 am

Think I know what the problem is.
The linear and angular damping was never set.

Just realized the NewtonBody class already had two members called m_lineardamping and m_angulardamping that were exposed in the editor. If you were changing those nothing happened.
What I implemented was only getters and setters that is used from within a script which totally ignored the above variables.
I've modified the code to apply the damping on body creation using the above editor values and modified the getter and setter to update the editor variables as well.

I also updated the plugin to work with the latest Newton version. I've temporarily had to disable(remove) the PlaneJoint and the UniversialJoint & UniversalActuator have been renamed to DoubleHinge & DoubleHingeActuator.

The joints have gone through some changes in Newton so some demos probably need to be updated for this. For example demo 6. The joints seems to move apart a little more than they did before so probably need to adjust some stiffness value or something.
Last edited by Sweenie on Mon Mar 19, 2018 3:52 am, edited 1 time in total.
Sweenie
 
Posts: 498
Joined: Mon Jan 24, 2005 7:59 am
Location: Sweden

Re: NewtonDynamics clumsy in Unity

Postby blackbird_dream » Mon Mar 19, 2018 3:43 am

Thks for your help. I'm not sure the issue comes from the damping coefficients as in my delphi demo they are set to the default values and it works fine. Also the behavior depends strongly on the timestep in unity , makes me think of looping problems.
anyway I'll test your build and make it sure.
Thks
User avatar
blackbird_dream
 
Posts: 354
Joined: Wed Jun 07, 2006 3:08 pm
Location: France

Re: NewtonDynamics clumsy in Unity

Postby Sweenie » Mon Mar 19, 2018 4:09 am

The damping definitely are affected by the timestep and hasn't anything to do with unity.
Running the simulation at 120 FPS with a damping of 0.1 will slow the fall more than running at 60 FPS.
The linear and angular damping is just a simple approach of relaxing the system a bit.
If you want proper realistic forces the damping should be set to zero and drag based on velocity and air friction should be implemented in your code instead.
Sweenie
 
Posts: 498
Joined: Mon Jan 24, 2005 7:59 am
Location: Sweden

Re: NewtonDynamics clumsy in Unity

Postby blackbird_dream » Mon Mar 19, 2018 5:28 am

I agree with you in theory of course.
However the order of magnitude of these quantities was satisfactory for the demo as you can see in the Delphi video. In Unity it was not.
Anyway I've tested your new build. Thks for updating it.
It gives the same result even with null damping. The cube motion is'nt correct as you can see in the video and test it by your self with the files attached.
https://ufile.io/3cfuq
User avatar
blackbird_dream
 
Posts: 354
Joined: Wed Jun 07, 2006 3:08 pm
Location: France

Re: NewtonDynamics clumsy in Unity

Postby Sweenie » Mon Mar 19, 2018 6:49 am

Hi.

Ok, found the problem, or rather problems... :)

First you are adding a constant force of 9.8 inside the ForceAndTorque callback, but you forgot to set the world gravity to zero so your are basically adding twice the gravity to the NewtonBody.
The world is already adding a gravity force to all bodies.

I realized this when logging the distance the bodies travelled after 3 seconds.
The newton body had travelled 88 units which is twice the expected 44 units.
But I also noticed your "manual" body had only travelled 30 units in the same time the Newtonbody had travelled 44 units.
It had to do with the Time.fixedtime you were using. The default fixed timestep in Unity is 0.02(50 fps) and Newton is running at 0.016(60 FPS).

Try changing your code to this...
Code: Select all
   static float fixedTime = 0;
    override public void OnApplyForceAndTorque(float timestep)
    {
      fixedTime += timestep;

        body.GetBody().AddForce(0, 0, Ftraction.z);
        //kineticcube.transform.position= new Vector3(0f, 0f, Time.fixedTime * Time.fixedTime * g  / 2);
      kineticcube.transform.position= new Vector3(0f, 0f, fixedTime * fixedTime * g  / 2);

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

Re: NewtonDynamics clumsy in Unity

Postby Sweenie » Mon Mar 19, 2018 7:02 am

Forgot to say, I believe Newton clamps the allowed damping values between 0.0 and 1.0 so setting damping values over 1.0 won't make a difference. 1.0 is max.
Sweenie
 
Posts: 498
Joined: Mon Jan 24, 2005 7:59 am
Location: Sweden

Re: NewtonDynamics clumsy in Unity

Postby blackbird_dream » Mon Mar 19, 2018 7:10 am

Great !
YOU are a really really clever hot chick !
Thks
User avatar
blackbird_dream
 
Posts: 354
Joined: Wed Jun 07, 2006 3:08 pm
Location: France

Re: NewtonDynamics clumsy in Unity [SOLVED not Clumsy unlike

Postby Sweenie » Mon Mar 19, 2018 7:14 am

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


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 30 guests

cron