car acceleration

Game Editor comments and discussion.

car acceleration

Postby Zehper48 » Thu Jul 20, 2006 10:50 pm

hi i have been serching through the forums but i couldnt find any answers.
i need my car to slowly acceleration when i press up and when i let go slowly stop. i dont really understand the variables so if you could be very spacific :D that would help the most :)
I like score
User avatar
Zehper48
 
Posts: 241
Joined: Sun Jun 11, 2006 1:34 am
Location: Advanced Noob
Score: 4 Give a positive score

Postby DilloDude » Thu Jul 20, 2006 11:40 pm

Create an accelerating variable. Make it an actor integer. Call it acc, because it's short. On keydown, up, at least one key is pressed, no repeat, add:
Code: Select all
acc = 1;

on keyup, up, add:
Code: Select all
acc = 0;

On draw actor, put
Code: Select all
if (acc)
{
    vel += .5;//vel is the name of your velocity variable, or use directional_velocity
}
else if (brake)// if you have a braking key, do a similar thing
{
    vel -= 1;
}
else
{
    vel -= .4;
}

if (vel < -2){vel = -2;}//limit the lowest speed
if (vel > 20){vel = 20;}//limit the highest speed

Play around with the numbers to get the desired result.
Image
User avatar
DilloDude
 
Posts: 866
Joined: Tue Jan 24, 2006 9:51 am
Location: Nyerellion
Score: 58 Give a positive score

Postby Zehper48 » Thu Jul 20, 2006 11:57 pm

i have just figured out about game editor not to long ago i dont really know how to create a variable. can you please help me :wink:
I like score
User avatar
Zehper48
 
Posts: 241
Joined: Sun Jun 11, 2006 1:34 am
Location: Advanced Noob
Score: 4 Give a positive score

Postby DilloDude » Fri Jul 21, 2006 4:46 am

Click on the 'variables' button in the script editor window. Click 'add'.
In the appropriate box, type the name of your variable. Then, choose whether it is integer, real, or string. Then choose whether it is a global or actor variable. Global variables are where there is one for the whole game, actor variables are ones that each actor has, like the defaults such as x, yvelocity, etc. Then choose if it is an array, and the size (an actor variable can't be an array). Arrays are a list of variables of the specified type, eg: array[0], array[3], etc. NOTE: if you set array size to 5, your array containers will be 0 - 4, not 1 - 5. If your variable is not an actor variable, you can put it in a save group if you want to save it. Then they can be saved and loaded with the saveVars and loadVars functions. When your done, click 'add'.
Image
User avatar
DilloDude
 
Posts: 866
Joined: Tue Jan 24, 2006 9:51 am
Location: Nyerellion
Score: 58 Give a positive score

Postby Zehper48 » Fri Jul 21, 2006 1:52 pm

when i put the code in there were alot of errors :( i dont know why
I like score
User avatar
Zehper48
 
Posts: 241
Joined: Sun Jun 11, 2006 1:34 am
Location: Advanced Noob
Score: 4 Give a positive score

Postby DilloDude » Fri Jul 21, 2006 11:48 pm

Create another variable called brake, and do similar things with it on keydown and keyup events for the down key.
Later on, to get a better result, you might want to use another variable for vel for now, but for now, just replace every occurence of 'vel' with 'directional_velocity'.
Image
User avatar
DilloDude
 
Posts: 866
Joined: Tue Jan 24, 2006 9:51 am
Location: Nyerellion
Score: 58 Give a positive score

Postby frodo » Tue Jul 25, 2006 2:56 pm

where is your car going? I mean, is it a rotating animation that you can drive in all directions? or is it just up and down the screen?

I can help you with both ways.
Whoever created GAME MAKER was very dumb!
User avatar
frodo
 
Posts: 127
Joined: Tue Mar 21, 2006 6:53 pm
Location: universe
Score: 2 Give a positive score

Postby Zehper48 » Sun Jul 30, 2006 2:56 pm

its going up,down,left and right
I like score
User avatar
Zehper48
 
Posts: 241
Joined: Sun Jun 11, 2006 1:34 am
Location: Advanced Noob
Score: 4 Give a positive score


Return to GE - General

Who is online

Users browsing this forum: No registered users and 1 guest

cron