PDA

View Full Version : realistic car



slyerguy
April 29th, 2006, 11:23 PM
can anyone tell me how to make a realistic car, a speedometer, and easy to change stats of the vehicle like max speed, handling, and acceleration?

Pasquale
April 30th, 2006, 12:02 AM
wowzers- that's a lot to ask- I say just start learning basic AS tutes

Nich
April 30th, 2006, 01:11 AM
No kidding... Man that's like a couple months worth of content... A speedometer wouln't be too hard, but the rest would be.

slyerguy
April 30th, 2006, 01:51 AM
well i found this tutorial on making a car but it wouldnt work when i used the code.

slyerguy
April 30th, 2006, 02:31 AM
i used the information in that tutorial i found and modified it to this. this works well but when you are accelerating forward, the car doesn't increase speed until you release the up arrow key.


onClipEvent(load){
speed = 0;
maxSpeed = 40;
minSpeed = -20;
}
onClipEvent(enterFrame){
if (Key.isDown(Key.UP)){
speed += 2;
} else {
if ((Key.isDown(Key.DOWN)) and speed >=0){
speed -= 5;
if ((Key.isDown(Key.DOWN)) and speed < 0){
speed -= 1;
} else {
speed *= .9;
}
}
if (speed >= maxSpeed){
speed -= 2;
} else if (speed <= minSpeed){
speed += 1;
}
if (Key.isDown(Key.LEFT)) {
_rotation -= speed;
}
if (Key.isDown(Key.RIGHT)) {
_rotation += speed;
}
x = Math.sin(_rotation*(Math.PI/180))*speed;
y = Math.cos(_rotation*(Math.PI/180))*speed*-1;
if (!_root.move.hitTest(_x+x, _y+y, true)) {
_x += x;
_y += y;
} else {
speed *= -.3;
}
}
}

slyerguy
April 30th, 2006, 02:40 AM
nevermind that last post i forgot to remove the "else {" so now i have a decent car, can anyone help me with the speedometer? i have figured out how to put in upgrades for the car so i won't need help with that anymore either

nathan99
April 30th, 2006, 06:29 AM
Heres one, not the best, not the worst

slyerguy
April 30th, 2006, 04:26 PM
ty that is way better than what i had before

slyerguy
April 30th, 2006, 09:15 PM
does anyone know how to make a tachometer and a gear shift

Pasquale
April 30th, 2006, 09:53 PM
LOL go the graphics.

@slyerguy- if ur jst gonna keep asking for things to be made- its kinda moving more toward a job request. This is kinda turning into a requests forum lol

slyerguy
April 30th, 2006, 10:57 PM
well this is the very last thing i need to know

Pasquale
April 30th, 2006, 11:36 PM
I'd say it's the first ;)

KIERIOSHIMOTO
May 1st, 2006, 12:02 AM
SlyerGuy:: Do some research...

Pasquale
May 1st, 2006, 01:45 AM
:) you can learn anything you want (pretty much) here - at these forums. Look @ source code- and the tutes :)

vini
May 1st, 2006, 04:16 AM
y dont you do some research. May be we can think on those lines and work on it

InfestedDemon
May 1st, 2006, 06:16 AM
well your very lucky to have nathan cut a peice of his brain temorarorly to bring you a flash. he's probs the best flash guy i know. your lucky

slyerguy
May 4th, 2006, 12:46 AM
I have this right now for tachometer but for some reason the gear is always 5 and even when i press the key to lower the gear, it goes to 4 then immediately back to 5 so if someone could help me fix this, it would be greatly appreciated.


var maxspeed:Number = 0;
var maxSpeedoRotation:Number = 160;
var accel:Number = -5;
var steer:Number = .08;
var drift:Number = .95;
var traction:Number = 10;
var holdArr:Array = [0, 0];
var angle:Number = 1;
var brakeForce:Number = .8;
var maxgamespeed:Number = 125;
var speed:Number = 0;
var maxRevs:Number = 10;
var gear:Number = 1;
var currentRevs:Number = 0;
var maxRevsRotation:Number = 180;
var maxSpeedGear1:Number = 3;
var maxSpeedGear2:Number = 7;
var maxSpeedGear3:Number = 12;
var maxSpeedGear4:Number = 18;
var maxSpeedGear5:Number = 25;

car.onEnterFrame = function() {
so._rotation = (speed/maxgamespeed*maxSpeedoRotation);
to._rotation = (currentRevs/maxRevs*maxRevsRotation);
car._rotation = angle*180/Math.PI;
if (gear = 1){
gearMaxSpeed = maxSpeedGear1;
maxspeed = maxSpeedGear1;
}
if (gear = 2){
gearMaxSpeed = maxSpeedGear2;
maxspeed = maxSpeedGear2;
}
if (gear = 3){
gearMaxSpeed = maxSpeedGear3;
maxspeed = maxSpeedGear3;
}
if (gear = 4){
gearMaxSpeed = maxSpeedGear4;
maxspeed = maxSpeedGear4;
}
if (gear = 5){
gearMaxSpeed = maxSpeedGear5;
maxspeed = maxSpeedGear5;
}
if (gear = 1){
currentRevs = speed/maxSpeedGear1;
}
if (gear = 2){
currentRevs = speed/maxSpeedGear2;
}
if (gear = 3){
currentRevs = speed/maxSpeedGear3;
}
if (gear = 4){
currentRevs = speed/maxSpeedGear4;
}
if (gear = 5){
currentRevs = speed/maxSpeedGear5;
}
if (Key.isDown(Key.CONTROL)){
gear += 1;
}
if (Key.isDown(Key.SHIFT)){
gear -= 1;
}
if (Key.isDown(Key.RIGHT) || Key.isDown(Key.LEFT)) {
angle += (Key.isDown(Key.RIGHT)-Key.isDown(Key.LEFT))*steer*(Math.abs(speed)<10 ? Math.abs(speed)/10 : 1)*1.3;
}
if (!Key.isDown(Key.UP)-Key.isDown(Key.DOWN)) {
speed *= drift;
} else if (Key.isDown(Key.UP)-Key.isDown(Key.DOWN) && !Key.isDown(Key.SPACE)) {
speed = Math.min(Math.max(speed+(Key.isDown(Key.UP)-Key.isDown(Key.DOWN))*.99, accel), maxspeed);
}
Math.abs(speed)<.99 ? speed=0 : null;
if (Key.isDown(Key.SPACE)) {
speed *= brakeForce;
if (speed>1) {
steer = .099;
}
traction = 50/3;
} else {
traction = Math.max(1, Math.abs((speed-10)/3));
steer = .08;
}
speed<0 ? traction=1.0 : null;
car._x -= holdArr[0] += ((Math.cos(angle)*speed)-holdArr[0])/traction;
car._y -= holdArr[1] += ((Math.sin(angle)*speed)-holdArr[1])/traction;
};

nathan99
May 4th, 2006, 03:00 AM
My GOD!!! Lol, If I can find a sec later I will look at it for you ;)

Dancso
May 4th, 2006, 04:46 PM
Heres one, not the best, not the worst That's awesome!! Too bad i got mx 6, and not 2004....:( so i cant load the source in mx6. Is there any way to solve this problem?
(Get mx2004 i guess..:/)

I would really need the source, because im making a game, and im in search for a good "car simulator" thingy, so if u could paste in the source, i'd be really happy.:)

EDIT: Pls hurry with the reply, im really goin out of time, i have to complete my game before may19th.:(

Dancso
May 6th, 2006, 11:31 AM
I'd really need the source!
Im doing a game-making competition on Jatekfejlesztes.hu (hungarian site)
If i'm not finished with my game before may 19, they'd think im a loser, who cant even make a good racing game.:(

I CAN make cars move, but those are really.... er... weak. I mean like the Flash MX Car component (or what....)
But it's really un-realistic.

Joppe
May 6th, 2006, 02:42 PM
Um, if its for an competition. Why should we help you.. Cheat? :S

JoshuaJonah
May 6th, 2006, 02:47 PM
Considering Nathan just gave you the code for the entire structure and engine of your game, I would say that is cheaing.

If i was hosting this competition and found that you were getting free code from an old master and copying it line for line, then on top of that, milking all the rest of the components out of people on an advanced actionscript forum, I would disqualify you.:|

slyerguy
May 8th, 2006, 08:53 PM
well i still havent figured out why the gears get stuck so could someone help me plz

nathan99
May 8th, 2006, 11:29 PM
Provide a FLA?

Nich
May 9th, 2006, 12:19 AM
Considering Nathan just gave you the code for the entire structure and engine of your game, I would say that is cheaing.

If i was hosting this competition and found that you were getting free code from an old master and copying it line for line, then on top of that, milking all the rest of the components out of people on an advanced actionscript forum, I would disqualify you.:|

Likewise.

nathan99
May 9th, 2006, 02:14 AM
and yes.. I'm in accordance with the other people.. I think I should enter :D

TheCanadian
May 9th, 2006, 02:36 AM
I have this right now for tachometer but for some reason the gear is always 5 and even when i press the key to lower the gear, it goes to 4 then immediately back to 5 so if someone could help me fix this, it would be greatly appreciated.
Your first problem is that you are using the assignment operator (=) instead of the comparison operator (==) in your if statements.

Pasquale
May 9th, 2006, 03:48 AM
I'm not sure you should help - unless you get full creadit for it guys. I'd hate to see somone ripped off.

hybrid101
May 9th, 2006, 04:16 AM
definitely join, nathan:D
and i know it isn't right to ask for fla's with all the code...especially when joining a comp end entering it:P
it would be worse if you won
oh and if i were you slyerguy, give us your fla. try fto make something first, then let us help when you're stuck

and google (www.google.com) is good

slyerguy
May 9th, 2006, 09:06 PM
first off thanks TheCanadian using == insted of = solved the problem with the gears but now can someone help me figure out how to change the rate of acceleration and also make it so holding down the gear key it will still only change one gear insted of keep changing. if you didnt understand that, the fla might help.

Mr.Pancake
May 26th, 2006, 08:51 AM
that handling and such starts off good i will keep an eye on this thread :)

slyerguy
July 31st, 2006, 07:19 PM
im still in need of some help

Joppe
July 31st, 2006, 07:37 PM
It changes many gears when holding down, what you need help with dude? :/

slyerguy
July 31st, 2006, 07:41 PM
i want it only changing one gear when u press the key even if u press and hold down the key.

Joppe
July 31st, 2006, 07:44 PM
here

slyerguy
July 31st, 2006, 07:49 PM
thanks thats just what i wanted

biznuge
July 31st, 2006, 08:41 PM
Why not just investigate into some basic physics and mathematics. RATE OF CHANGE might be especially helpful to you, as would "torque" and "turning effects"

Here's an oldish idea I haven't got around to finishing off though! might help you with momentum and things.

Car Tilez (http://www.biznuge.co.uk/cargame/)

Cursor keys to control, and space bar for handbrake guys!!!