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 / [dark dynamix] can I set an immediate speed or force to push my cube?

Author
Message
Alduce
23
Years of Service
User Offline
Joined: 26th Oct 2002
Location: Rama spaceship
Posted: 23rd Oct 2012 13:59 Edited at: 23rd Oct 2012 15:23
Hi all,
I am handling with Dark Dynamix with GREAT results!.
I am really near to finish the conversion of my best Newton project to the new DarkDynamix engine.

I notice too that the code lines are really little than before.

So, here the little thing I can't do for now..

I would to give a force to a body, so I prepare a little code (this code is inside the main loop):



Ok, independently from the mass/force needed argument (this 53000.0 force parameter give to object a good push, not strenght and not too little too, considering the mass of the object)
I would that my object,instantly, get a push of force.

So when I push "f" key my object will be pushed with INFINITE ACCELLERATION, from speed =0 to speed 53000, I repeat, instantly.

With this code when I push "f" key I get 1 and only 1 cycle of the code where the FORCE is generated.


So, my object don't get an immediate speed.. my object seems stopped as well..

Okok, now I change the code in this way:


I made an infinite cycle number, so nothing change "key_pushed = 1 case" then I get the DYN ADD FORCE command is runned in every cycle of my game.

In this way I see my cube get pushed with a big accelleration and it's moving!.
At this point I understand this command give just an ADDING of force..
So If I always repeat this command I obtain a growing speed of my cube.

IN FINISH MY HELP REQUEST!:
1) How can I set a immediate force of my cube object?
and (or?)
(seems not exist some command like "SET_VELOCITY or SET_SPEED")

2)How can I set an immediate SPEED of my cube object?


(sincerely I don't understand well if these 2 questions are in fact the same thing... haha I am melted dudes!..
)


EDIT : I realize now I prepared the topic for DarkDynamix Thread but posted on DBPro.. Please, switch this topic in DarkDynamix thread If is needed.
Andrew_Neale
16
Years of Service
User Offline
Joined: 3rd Nov 2009
Location: The Normandy SR-2
Posted: 23rd Oct 2012 20:46 Edited at: 24th Oct 2012 00:36
To give an object instant speed you need to look at the common physics equation:

F = M * A
Force = Mass * Acceleration

Because you want the speed to be instant, you can ignore the time aspect of acceleration and just give it the speed you want. Mass will be the mass you gave the object in Dark Dynamix. So if you made a cube with mass of 10 and want to give it a speed of 50 you would need to give it a force of 50 * 10 = 500. Now because this would be the acceleration required to reach a speed of 50 over 1 second, you'll need to multiply it by your frame rate so that you only need to apply it to the current frame rather than all of them for the next second. So in this example, if we were running at 60 frames per second, this would give you 500 * 60 = 30000. However, this doesn't take into account the friction against the ground or the air resistance.

As an example of the scale of forces you may need to apply, here is some code I was using in a quick test to generate and fire a projectile.



As you can see there, the sphere only has a mass of about 8 (volume of the sphere multiplied by the density) and I needed to apply a force of 50000 to it to get a suitable projectile velocity.


Previously TEH_CODERER.
Alduce
23
Years of Service
User Offline
Joined: 26th Oct 2002
Location: Rama spaceship
Posted: 23rd Oct 2012 23:26
mmm yes, maybe I start to understand what is the situation about forces related to the mass.
Probably my question was many confused too. In fact I done some little code modifications and now it work as I want.


Andrew_Neale
16
Years of Service
User Offline
Joined: 3rd Nov 2009
Location: The Normandy SR-2
Posted: 24th Oct 2012 00:31
Good, it is useful to have at least a little knowledge of physics so that you can get the best results out of a physics engine. Glad to hear you have it working now.


Previously TEH_CODERER.

Login to post a reply

Server time is: 2026-07-07 17:31:09
Your offset time is: 2026-07-07 17:31:09