Gamestudio Links
Zorro Links
Newest Posts
loading historical data 1st time
by AndrewAMD. 04/14/23 12:54
Trade at bar open
by juanex. 04/13/23 19:43
Bug in Highpass2 filter
by rki. 04/13/23 09:54
Adding Limit Orders For IB
by scatters. 04/11/23 16:16
FisherN
by rki. 04/11/23 08:38
AUM Magazine
Latest Screens
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Hecknex World
Who's Online Now
3 registered members (AndrewAMD, Grant, Neb), 908 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
rki, FranzIII, indonesiae, The_Judge, storrealba
18919 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 | chip programmers | 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