Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
2 registered members (TipmyPip, AndrewAMD), 12,726 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Need Help with car race script... #290165
09/17/09 15:55
09/17/09 15:55
Joined: Sep 2009
Posts: 22
Boca Raton, Florida
M
MarcsVision Offline OP
Newbie
MarcsVision  Offline OP
Newbie
M

Joined: Sep 2009
Posts: 22
Boca Raton, Florida
i am working on a car racing game and want to know what script should i use to calculate acceleration of the players car.

In im script im using an if/else statement:

if (my.car_speed < (my.max_speed * time))
{
my.car_speed += 1 * time; // increase the speed of the car
}
else //
{
my.car_speed -= 0.5 * time; // decrease the speed of the car
}

i have Max_speed defined as skill23 and car_speed defined as skill27. but i keep getting a syntrex error. can anyone help or give me a better script to use.

thanks alot

-Marc

Re: Need Help with car race script... [Re: MarcsVision] #304550
01/08/10 19:02
01/08/10 19:02
Joined: Nov 2005
Posts: 66
Spokane, WA, USA
Vonman Offline
Junior Member
Vonman  Offline
Junior Member

Joined: Nov 2005
Posts: 66
Spokane, WA, USA
If I understand you correctly, you want to calculate the acceleration rate rather than speed or the force that pushes the car..

A tip, in a function,
set temp to the current speed of the car...
Then, in the next frame, set whatever variable you use as "acceleration speed" like this.

accell = (current_speed - temp) * time_step;


The goal is to compare how many units the mph/kph has increase in each from relative from the previous frame.

If frame 1 you're going 50 mph and in the next from you're going 55, you've accelerated at a rate of 5 mph per frame (which is actualy pretty fast!).

Another thing is you have to multiply the result by time_step or any difference in the framerate will render the results inaccurate.

It might be something like this.
////////////////////////////////////////////
var speedmph;
var accell_rate;

(c-script style example)
function calc_accell_speed()
{
while(1)
{
temp = speedmph; //OR YOUR speed variable
wait(1);
accell_rate = (speedmph - temp) * time_step;
//// acceleration is mph in current frame MINUS mph in the previous from - compensated by timestep.


}
}
///////////////////////////////////////////


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