Gamestudio Links
Zorro Links
Newest Posts
Lapsa's very own thread
by Lapsa. 01/30/26 19:44
Zorro version 3.0 prerelease!
by TipmyPip. 01/30/26 13:36
Historical Data with the 64bit FXCM Plugin
by Martin_HH. 01/28/26 18:45
ZorroGPT
by TipmyPip. 01/28/26 09:48
SGT_FW
by Aku_Aku. 01/27/26 15:10
Buy A8 Pro Version
by Ezzett. 01/26/26 14:22
C++ direct start requires Zorro S
by jcl. 01/23/26 14:29
AUM Magazine
Latest Screens
Dorifto samurai
Shadow 2
Rocker`s Revenge
Stug 3 Stormartillery
Who's Online Now
0 registered members (), 11,470 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Sfrdragon, mayarik, Castromangos, Quantum, stephensdeborah
19195 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