Gamestudio Links
Zorro Links
Newest Posts
ZorroGPT
by TipmyPip. 08/17/26 19:28
Max Number of Strategies in /Strategy folder
by Martin_HH. 08/17/26 07:54
Pause button for evaluation shell?
by AndrewAMD. 08/13/26 17:16
Sam Foster Sound | Experienced Game Composer for Hire
by titanicpiano14. 08/10/26 12:46
phantom() not defined in indicators.c
by jcl. 08/07/26 11:45
Accepting new programming clients
by AndrewAMD. 08/06/26 21:25
AUM Magazine
Latest Screens
Dorifto samurai
Shadow 2
Rocker`s Revenge
Stug 3 Stormartillery
Who's Online Now
2 registered members (swingtraderkk, TipmyPip), 10,815 guests, and 9 spiders.
Key: Admin, Global Mod, Mod
Newest Members
riggi89, shuhari, KD1990, Student_64151, Koti
19230 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