Gamestudio Links
Zorro Links
Newest Posts
Executing Trades on Next Bar Open
by vicknick. 06/13/24 08:51
Zorro Beta 2.61: PyTorch
by jcl. 06/10/24 14:42
New FXCM FIX Plugin
by flink. 06/04/24 07:30
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (henrybane), 1,246 guests, and 8 spiders.
Key: Admin, Global Mod, Mod
Newest Members
AemStones, LucasJoshua, Baklazhan, Hanky27, firatv
19059 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