Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Some times I think logic is illogic..

Author
Message
Alduce
23
Years of Service
User Offline
Joined: 26th Oct 2002
Location: Rama spaceship
Posted: 19th Oct 2012 19:32 Edited at: 19th Oct 2012 19:52
haha hi again dudes.. I am trying to fight against Newton engine.. It's really cool but bad as a giant black spider..

Take a look to this really simple code. If I press UP arrow key I give permission to a newton force to push my cube in X coord.
If I press DOWN arrow I remove the permission to that newton force.
All that using the ok_movement variable 1 or 0.

This is the main loop of my program:



You can notice the variable ok_movement is set to 0 before the start of main loop.
So, this code is NOT WORKING.. I can give and remove the permission (the ok_movement flag) to the Newton force but nothing appear and nothing moving...
Ok so now take a look at the following code:



yes, exactly, it's the same code of before but in this case the variable ok_movement is set to 1 before the main loop..
So when the main loop start the cube is receiving the Newton push until I press the DOWN arrow key.
So with DOWN key I stopped the cube and now (BEFORE THE CUBE STOPPED COMPLETLY), If I press UP key again so the cube back to move! (BUT ONLY IF I do not waited for it to stop completely!!)

IN FINISH:
If I start the main loop with the ok_movement variable set (before the main loop) to 0, never I will can use the Newton force to push my cube

But If I start the main loop with previously set the ok_variable to 1 so I get my cube moving and from now I can stop it and back to let it get pushed again.. (BUT ONLY IF NEVER IT STOPPED COMPLETLY....... IF NOT NEVER AGAIN I WILL CAN MOVE IT AGAIN....)

WHY THE HELL ALL THAT?? Sorry but I can reach it..








PS: here the complete code if you want to test it:
Andrew_Neale
16
Years of Service
User Offline
Joined: 3rd Nov 2009
Location: The Normandy SR-2
Posted: 19th Oct 2012 20:40
You just need to add this line to where you are applying the velocity:

NDB_NewtonWorldUnFreezeBody cube1

The body "freezes" after being stationary for a certain amount of time to improve performance so the velocity won't have an effect. This command just brings it back into action.

I tested it in your code and it definitely did the trick.


Previously TEH_CODERER.
Dar13
18
Years of Service
User Offline
Joined: 12th May 2008
Location: Microsoft VisualStudio 2010 Professional
Posted: 19th Oct 2012 20:49 Edited at: 19th Oct 2012 20:49
When working with physics engines, it's best to use forces to propel your object instead of just setting the velocity.

Been a while since I've used Newton, but I think this code would work:


You'll notice that your object will accelerate a lot faster, but is also smoother.

EDIT: I see I got ninja'd.

Alduce
23
Years of Service
User Offline
Joined: 26th Oct 2002
Location: Rama spaceship
Posted: 19th Oct 2012 21:46 Edited at: 19th Oct 2012 21:50
@Andrew_Neale
and
@Dar13
Thank you REALLY MUCH dudes!
Physic engines are really cool to make a 3D game but without some help like your I think I could not go on..


Ps. the NDB_NewtonWorldUnFreezeBody command is necessary (as Andrew wrote)in all the ways!

Login to post a reply

Server time is: 2026-07-10 18:55:41
Your offset time is: 2026-07-10 18:55:41