Gamestudio Links
Zorro Links
Newest Posts
WFO Training with parallel cores Zorro64
by Martin_HH. 02/24/26 19:51
Zorro version 3.0 prerelease!
by TipmyPip. 02/24/26 17:09
ZorroGPT
by TipmyPip. 02/23/26 21:52
Camera always moves upwards?
by clonman. 02/21/26 09:29
Sam Foster Sound | Experienced Game Composer for Hire
by titanicpiano14. 02/19/26 13:22
AUM Magazine
Latest Screens
Dorifto samurai
Shadow 2
Rocker`s Revenge
Stug 3 Stormartillery
Who's Online Now
4 registered members (Martin_HH, TipmyPip, AndrewAMD, Grant), 5,825 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
alx, ApprenticeInMuc, PatrickH90, USER0328, Sfrdragon
19199 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Phent_setvelocity? #59347
11/19/05 10:53
11/19/05 10:53
Joined: Mar 2003
Posts: 4,427
Japan
A
A.Russell Offline OP
Expert
A.Russell  Offline OP
Expert
A

Joined: Mar 2003
Posts: 4,427
Japan
I'm looking for an easy way to start multiple physics objects moving at the same speed regardless of their mass. A phent_setvelocity function would be nice, but since I don't see one, what would be an alternative?

Re: Phent_setvelocity? [Re: A.Russell] #59348
11/19/05 17:47
11/19/05 17:47
Joined: Mar 2003
Posts: 5,377
USofA
fastlane69 Offline
Senior Expert
fastlane69  Offline
Senior Expert

Joined: Mar 2003
Posts: 5,377
USofA
if v(initial) = zero

velocity(final) = Force x Time / Mass


Quite simply, gauged by your mass and given that you want to do this in one timestep, simply apply a force for one frame that will give you the desired velocity. Just as good as a set_velocity command.

Re: Phent_setvelocity? [Re: fastlane69] #59349
11/20/05 14:01
11/20/05 14:01
Joined: Mar 2003
Posts: 4,427
Japan
A
A.Russell Offline OP
Expert
A.Russell  Offline OP
Expert
A

Joined: Mar 2003
Posts: 4,427
Japan

Thanks,

Since time is always 1 (tick):

Force = velocity * mass

... and they all move at the same speed!

Re: Phent_setvelocity? [Re: A.Russell] #59350
11/20/05 17:02
11/20/05 17:02
Joined: Mar 2003
Posts: 5,377
USofA
fastlane69 Offline
Senior Expert
fastlane69  Offline
Senior Expert

Joined: Mar 2003
Posts: 5,377
USofA
That is only true if the objects you are applying the force to also have the same mass.

If you want to use this technique for different massed objects, just gauge the force according to the mass. Here is an easy way (keeping in mind that our time is always 1 tick):

1) Choose a base mass and a base velocity. This will give you a base force to apply and thus
v(o) = F(o)/m(o).

2) Choose a different mass car. It's mass is m(a) and thus
v(a) = F(a)/m(a).

3) Set v(a) = v(o) so that both cars are traveling at teh same speed after one tick
F(o)/m(o)=F(a)/m(a).

4) Solving for F(a) (the force are applying to the second car) we find that
F(a) = F(o)*(m(a)/m(o))

Conclusion:
You will need to apply the original force multiplied by the ratio of the second mass to the first in order for both cars to travel the same speed after one tick. So if the second car is more massive than the first, you need to apply a larger force; if it's less massive, you apply a smaller force This will make sure that no matter what the mass of the car, you are always applying a force that will make it move a set speed after one tick.

Re: Phent_setvelocity? [Re: fastlane69] #59351
11/21/05 03:08
11/21/05 03:08
Joined: Mar 2003
Posts: 4,427
Japan
A
A.Russell Offline OP
Expert
A.Russell  Offline OP
Expert
A

Joined: Mar 2003
Posts: 4,427
Japan
Hmn, now I'm confused. I'm not good at mathematical notation, could you show me how that looks in script?

I want to make sure that I've got this right, so here is what I did:

Code:

//set the velocity for all objects in group
initial_velocity = random(10000)+10000;

//Set mass individually
my.meteor_mass = random(8)+2;


//Calculate the amount of force required to get each object up to the target
//velocity in one frame

//***LOOK HERE***
//velocity = force * time/mass
//time is always 1 in this case
//since we want to reach the target velocity in one frame
//and so, force(to aply to the object) = velocity(target) * mass(of object to be pushed) ???????
meteor_force = initial_velocity * my.meteor_mass;

//set direction
vec_normalize(meteor_direction,1);
vec_scale(meteor_direction, meteor_force);

//push object in direction with right amount of force
phent_addforcelocal(my, meteor_direction.x,vector(random(1000)-500,random(1000)-500,random(1000)-500) );



This appears to be working, the asteroids seem to be moving at the same speed, but I'd like to have it spot on. What should the formula be for calculating the force? (ideally in a computer algorithm).

Re: Phent_setvelocity? [Re: A.Russell] #59352
11/21/05 17:38
11/21/05 17:38
Joined: Mar 2003
Posts: 5,377
USofA
fastlane69 Offline
Senior Expert
fastlane69  Offline
Senior Expert

Joined: Mar 2003
Posts: 5,377
USofA
I'm just mathematically masturbating, sorry....All I've done is take velocity out of the equation where you kept it in.

You should be good to go.

Try this to be sure...increase the random mass to 100 so you get greater spread in mass and see if you 'roids still behaive the way you want them to.

Re: Phent_setvelocity? [Re: fastlane69] #59353
11/22/05 11:45
11/22/05 11:45
Joined: Mar 2003
Posts: 4,427
Japan
A
A.Russell Offline OP
Expert
A.Russell  Offline OP
Expert
A

Joined: Mar 2003
Posts: 4,427
Japan
Yep, they're still okay. Looks like you had it right the first time

Thanks a lot for your help.


Moderated by  HeelX, Spirit 

Gamestudio download | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1