PDA

View Full Version : Car Problem


c00lryguy
11-27-2004, 11:57 PM
Ok so I made a car movieclip and inside the car movieclip I have two wheels and in the code for the car i have:

onClipEvent (enterFrame) {
if (Key.isDown(Key.RIGHT)) {
speed += 5;
setProperty("Wheel1", _rotation, speed);
setProperty("Wheel2", _rotation, speed);
} else {
if (Key.isDown(Key.LEFT)) {
speed -= 5;
setProperty("Wheel1", _rotation, speed);
setProperty("Wheel2", _rotation, speed);
} else {
speed *= .9
}
}
if (Math.abs(speed)>255) {
speed *= .6;
}
speed *= .9;
x = Math.cos(_rotation*(Math.PI/180))*speed*+1;
if (!_root.move.hitTest(_x+x, _y+y, true)) {
_x += x;
} else {
speed *= -.3;
}
}


and I'm trying to make the wheels turn with the car, how would I do this?

Nexus
11-28-2004, 09:17 AM
I did this up quickly, since I didn't like your method of doing things...

Car Wheels (http://xsdsx.250free.com/temp/carwheels.swf)
Source (http://xsdsx.250free.com/temp/carwheels.fla)

Hope this helps you out.

c00lryguy
11-28-2004, 01:58 PM
well the thing is, its not top view like yours, its side view like your sig

The Brown Cow
11-28-2004, 02:07 PM
Just trying to make the wheels spin then?

First off, forget about setProperty(). That's been outdated since Flash 5. Use dot syntax instead. It's much easier to understand.

// Rather than...
setProperty("Wheel1", _rotation, speed);
// Use...
Wheel1._rotation = speed;

Anyway, if you just want the wheels to spin when the keys are pressed..
onClipEvent(enterFrame) {
if (Key.isDown(Key.LEFT)) {
speed -= 5;
} else if (Key.isDown(Key.RIGHT)) {
speed += 5;
}
Wheel1._rotation += speed;
Wheel2._rotation += speed;
}
If the left key is pressed, we lower the speed. If the right key is pressed, we increase the speed. We then rotate the wheels by the current speed.

c00lryguy
11-28-2004, 02:13 PM
i tried "Wheel1._rotation = speed;" and it doesnt work
they dont move

heres what i have so far

http://img93.exs.cx/my.php?loc=img93&image=Car.swf

http://c00lryguy.250x.com/car.fla

The Brown Cow
11-28-2004, 02:35 PM
Your wheels don't have instance names. Use the property inspector to name them Wheel1 and Wheel2.

Also, when you use setProperty, you set the value of the wheel's rotation equal the the current speed. So what you have are more like speedometers. As the speed increases, they turn to the right, as it decreases, they turn back toward the right.
If you were to add the current speed to the wheel's rotation property, then the wheels will spin faster according to the speed.

[flash width=500 height=100 loop=false:3dbece55d6]http://browncowinternational.com/temp/car.swf[/flash:3dbece55d6]
(The line is just there for reference.)

Right-click to download: http://browncowinternational.com/temp/car.fla

c00lryguy
11-28-2004, 02:41 PM
THANK YOU!!!
w00t

Freddy
11-28-2004, 02:45 PM
whoa... nice car.

wheels still dont look right though.

just have tham animated moving. then when the key is down, it plays.

no one will be able to tell anyway. if it wasnt for that huge line, I wouldn't have.

c00lryguy
11-28-2004, 03:25 PM
no that line is for referance, ill get rid of that

MercuryLime
11-28-2004, 05:21 PM
I know, but without it it doesn't really matter because you can't tell they are rotating.

c00lryguy
11-28-2004, 05:29 PM
I made it bigger in mine
I'll show the end result later

Also, how would I set a dynamic textboxes text in actoinscript like spd.text = speed
um...that doesnt work, btw

EDIT: nvm i got it...i forgot to put _root before the instance name :x

The Brown Cow
11-28-2004, 06:02 PM
First give the text box and instance name, we'll use speedOutput for this example.
Now, if you want to display the contents of a variable named speed...
speedOutput.text = speed;

Since you're working with code inside a movie clip, you may need to prefix the text box's name with _root, depending on where you have the text box.

c00lryguy
11-28-2004, 06:43 PM
yeah i foun out a lil while ago but i now have a new problem

this is what i have so far:
http://img111.exs.cx/my.php?loc=img111&image=Car2.swf

what i want is for when i go backwards, it will stop near the edge so it will still go backwards but not actually moving backwards(effect of a moving camera) and the same for forwards

oh uh right for gas, left for reverse, and down for hand brakes

c00lryguy
11-28-2004, 07:40 PM
hmm i tried hittest and that didnt work :/

MercuryLime
11-28-2004, 09:19 PM
There's a very simple solution involving some code that I'll get for you tomorrow.

c00lryguy
11-29-2004, 10:53 PM
nexus, I want my car flash to look like your apache sig

oh, and update on the car flash
http://img8.exs.cx/my.php?loc=img8&image=Car3.swf

Nexus
11-30-2004, 03:38 PM
For that I simply made and if statement that said something like...

if (_x<_width/2) {
_x = _width/2;
/*
code to make background scroll here
*/
}

c00lryguy
11-30-2004, 04:02 PM
awsome thank you! ^.^