Groups | Blog | Home
all groups > flash actionscript > april 2005 >

flash actionscript : kGlad


davidprovost
4/3/2005 8:31:57 PM
Hey kGlad, I gotta question... I asked u earlier about adding psychics to
acceleration and what u told me works perfectly, but how would I add psyhics to
the rotatin part to, and how would I make it so that the car cant rotate unless
its moving? degtoRad = Math.PI/180; speed = 0; maxSpeed = 20; moveI =
setInterval(moveF, 40, car_mc); function moveF(mc) { if (Key.isDown(Key.LEFT))
{ mc._rotation -= 5; } if (Key.isDown(Key.RIGHT)) { mc._rotation += 5; } if
(Key.isDown(Key.UP)) { if (speed<=maxSpeed) { speed = .9*speed+.1*maxSpeed; } }
else if (Key.isDown(Key.DOWN)) { if (speed>=-maxSpeed) { speed =
..9*speed-.1*maxSpeed; } } else { speed = .9*speed; } mc._x +=
speed*Math.cos(degtoRad*mc._rotation); mc._y +=
speed*Math.sin(degtoRad*mc._rotation); } stop();
kglad
4/3/2005 8:37:37 PM
oh, i misunderstood your post in the other thread. we can add the following to
prevent turning unless moving:

degtoRad = Math.PI/180;
speed = 0;
maxSpeed = 20;
moveI = setInterval(moveF, 40, car_mc);
function moveF(mc) {

if (Key.isDown(Key.LEFT)&&Math.abs(speed)>0) {
mc._rotation -= 5;
}
if (Key.isDown(Key.RIGHT)&&Math.abs(speed)>0) {
mc._rotation += 5;
}
if (Key.isDown(Key.UP)) {
if (speed<=maxSpeed) {
speed = .9*speed+.1*maxSpeed;
}
} else if (Key.isDown(Key.DOWN)) {
if (speed>=-maxSpeed) {
speed = .9*speed-.1*maxSpeed;
}
} else {
speed = .9*speed;
}
mc._x += speed*Math.cos(degtoRad*mc._rotation);
mc._y += speed*Math.sin(degtoRad*mc._rotation);
}
stop();
davidprovost
4/3/2005 8:42:25 PM
kglad
4/3/2005 8:46:27 PM
oh, i forgot. speed never reaches zero with the old code. this will fix it:

degtoRad = Math.PI/180;
speed = 0;
maxSpeed = 20;
moveI = setInterval(moveF, 40, car_mc);
function moveF(mc) {

if (Key.isDown(Key.LEFT)&&Math.abs(speed)>0) {
mc._rotation -= 5;
}
if (Key.isDown(Key.RIGHT)&&Math.abs(speed)>0) {
mc._rotation += 5;
}
if (Key.isDown(Key.UP)) {
if (speed<=maxSpeed) {
speed = .9*speed+.1*maxSpeed;
}
} else if (Key.isDown(Key.DOWN)) {
if (speed>=-maxSpeed) {
speed = .9*speed-.1*maxSpeed;
}
} else {
speed = .9*speed;
if(Math.abs(speed)<1){
speed=0;
}
}
mc._x += speed*Math.cos(degtoRad*mc._rotation);
mc._y += speed*Math.sin(degtoRad*mc._rotation);
}
stop();
davidprovost
4/3/2005 8:50:32 PM
kglad
4/3/2005 10:45:00 PM
degtoRad = Math.PI/180;
speed = 0;
maxSpeed = 20;
moveI = setInterval(moveF, 40, car_mc);
function moveF(mc) {

if (Key.isDown(Key.LEFT)&&Math.abs(speed)>0) {
mc._rotation -= 5;
}
if (Key.isDown(Key.RIGHT)&&Math.abs(speed)>0) {
mc._rotation += 5;
}
if (Key.isDown(Key.UP)) {
if (speed<=maxSpeed) {
speed = .9*speed+.1*maxSpeed;
}
} else if (Key.isDown(Key.DOWN)) {
if (speed>=-maxSpeed) {
speed = .9*speed-.1*maxSpeed;
}
} else if (Key.isDown(Key.SPACE)) {
speed = .7*speed; // set braking amount here
} else {
speed = .99*speed; // set rate of slowing when coasting here
}
if(Math.abs(speed)<1){
speed=0;
}
mc._x += speed*Math.cos(degtoRad*mc._rotation);
mc._y += speed*Math.sin(degtoRad*mc._rotation);
}
stop();
davidprovost
4/4/2005 5:02:32 AM
wieniecomponents
4/4/2005 5:10:26 AM
The skid marks and the exhaust effects can be simple movieclips.
Just use the _alpha property to fade the mc's whenever it turns or stops
suddenly.
the exhaust effect can be a nested mc in the car, which can be played until a
particular speed is reached...
davidprovost
4/4/2005 5:20:12 AM
davidprovost
4/4/2005 5:38:15 AM
What Im looking for in the car psychics is something like this:
http://www.markfennell.com/flash/
kglad
4/5/2005 12:00:00 AM
create a new movieclip. align your car with the top right of the stage center
facing east. put two skid marks behind the car (to the left of stage-center).
remove the car from this moviecip. right click on this movieclip and click
linkage, tick export for actionscript and give it a linkage ID = skids. you
can then use the following code:

degtoRad = Math.PI/180;
speed = 0;
maxSpeed = 20;
ivar = 0;
moveI = setInterval(moveF, 20, car_mc);
function moveF(mc) {
if (Key.isDown(Key.LEFT) && Math.abs(speed)>0) {
if (speed>15) {
ivar++;
rclip = _root.attachMovie("skids", "skid"+ivar, ivar);
rclip._rotation=mc._rotation;
rclip._x = mc._x;
rclip._y = mc._y;
}
mc._rotation -= 5;
}
if (Key.isDown(Key.RIGHT) && Math.abs(speed)>0) {
if (speed>15) {
ivar++;
rclip = _root.attachMovie("skids", "skid"+ivar, ivar);
rclip._rotation=mc._rotation;
rclip._x = mc._x;
rclip._y = mc._y;
}
mc._rotation += 5;
}
if (Key.isDown(Key.UP)) {
if (speed<=maxSpeed) {
speed = .9*speed+.1*maxSpeed;
}
} else if (Key.isDown(Key.DOWN)) {
if (speed>=-maxSpeed) {
speed = .9*speed-.1*maxSpeed;
}
} else if (Key.isDown(Key.SPACE)) {
speed = .7*speed;
// set braking amount here
} else {
speed = .99*speed;
// set rate of slowing when coasting here
}
if (Math.abs(speed)<1) {
speed = 0;
}
mc._x += speed*Math.cos(degtoRad*mc._rotation);
mc._y += speed*Math.sin(degtoRad*mc._rotation);
updateAfterEvent();
}
stop();
davidprovost
4/5/2005 7:12:03 AM
Awesome! But just one more thing, I cant get the skid marks to show up under
the car, whenever u drive back over them they are ontop of the car. And how do
I get them to dissappear after a couple seconds?
Mescalina79
4/5/2005 12:37:00 PM
LazLong
4/5/2005 1:46:55 PM
kglad
4/5/2005 2:06:50 PM
here's the car over the skids and the skids fading and being removed:

degtoRad = Math.PI/180;
speed = 0;
maxSpeed = 20;
ivar = 0;
car_mc.swapDepths(100000);
moveI = setInterval(moveF, 20, car_mc);
function moveF(mc) {
if (Key.isDown(Key.LEFT) && Math.abs(speed)>0) {
if (speed>15) {
ivar++;
rclip = _root.attachMovie("skids", "skid"+ivar, ivar);
rclip._rotation = mc._rotation;
rclip._x = mc._x;
rclip._y = mc._y;
}
mc._rotation -= 5;
}
if (Key.isDown(Key.RIGHT) && Math.abs(speed)>0) {
if (speed>15) {
ivar++;
rclip = _root.attachMovie("skids", "skid"+ivar, ivar);
rclip._rotation = mc._rotation;
rclip._x = mc._x;
rclip._y = mc._y;
}
mc._rotation += 5;
}
if (Key.isDown(Key.UP)) {
if (speed<=maxSpeed) {
speed = .9*speed+.1*maxSpeed;
}
} else if (Key.isDown(Key.DOWN)) {
if (speed>=-maxSpeed) {
speed = .9*speed-.1*maxSpeed;
}
} else if (Key.isDown(Key.SPACE)) {
speed = .7*speed;
// set braking amount here
} else {
speed = .99*speed;
// set rate of slowing when coasting here
}
if (Math.abs(speed)<1) {
speed = 0;
}
mc._x += speed*Math.cos(degtoRad*mc._rotation);
mc._y += speed*Math.sin(degtoRad*mc._rotation);
if (ivar) {
for (jvar=0; jvar<=ivar; jvar++) {
if (_root["skid"+jvar]) {
_root["skid"+jvar]._alpha -= 5;
if (_root["skid"+jvar]._alpha<=0) {
_root["skid"+jvar].removeMovieClip();
}
}
}
}
updateAfterEvent();
}
stop();
davidprovost
4/5/2005 6:59:17 PM
davidprovost
4/5/2005 10:49:50 PM
davidprovost
4/5/2005 11:50:29 PM
kglad
4/6/2005 12:48:22 AM
to get the skid marks to fade slower change:

_root["skid"+jvar]._alpha -= 5; // use a number smaller than 5 to make the
skids remain longer

to add skids to the brakes change the following lines:

} else if (Key.isDown(Key.SPACE)) {
speed = .7*speed;
// set braking amount here
} else {

to:

} else if (Key.isDown(Key.SPACE)) {
speed = .7*speed;
if (speed>0) {
ivar++;
rclip = _root.attachMovie("skids", "skid"+ivar, ivar);
rclip._rotation = mc._rotation;
rclip._x = mc._x;
rclip._y = mc._y;
}
} else {
kglad
4/6/2005 1:11:17 AM
to move a map instead of the car use:

degtoRad = Math.PI/180;
speed = 0;
maxSpeed = 20;
ivar = 0;
car_mc.swapDepths(100000);
moveI = setInterval(moveF, 20, map_mc); // <-- map_mc is the map instance
name
function moveF(mc) {
if (Key.isDown(Key.LEFT) && Math.abs(speed)>0) {
if (speed>15) {
ivar++;
rclip = _root.attachMovie("skids", "skid"+ivar, ivar);
rclip._rotation = mc._rotation;
rclip._x = mc._x;
rclip._y = mc._y;
}
mc._rotation += 5; // <--- this is a change
}
if (Key.isDown(Key.RIGHT) && Math.abs(speed)>0) {
if (speed>15) {
ivar++;
rclip = _root.attachMovie("skids", "skid"+ivar, ivar);
rclip._rotation = mc._rotation;
rclip._x = mc._x;
rclip._y = mc._y;
}
mc._rotation -= 5; // <--- this is a change
}
if (Key.isDown(Key.UP)) {
if (speed<=maxSpeed) {
speed = .9*speed+.1*maxSpeed;
}
} else if (Key.isDown(Key.DOWN)) {
if (speed>=-maxSpeed) {
speed = .9*speed-.1*maxSpeed;
}
} else if (Key.isDown(Key.SPACE)) {
speed = .7*speed;
if (speed>0) {
ivar++;
rclip = _root.attachMovie("skids", "skid"+ivar, ivar);
rclip._rotation = mc._rotation;
rclip._x = mc._x;
rclip._y = mc._y;
}
} else { speed = .99*speed;
// set rate of slowing when coasting here
}
if (Math.abs(speed)<1) {
speed = 0;
}
mc._x -= speed*Math.cos(degtoRad*mc._rotation); // <--- this is a change
mc._y -= speed*Math.sin(degtoRad*mc._rotation); // <--- this is a change
if (ivar) {
for (jvar=0; jvar<=ivar; jvar++) {
if (_root["skid"+jvar]) {
_root["skid"+jvar]._alpha -= 5;
if (_root["skid"+jvar]._alpha<=0) {
_root["skid"+jvar].removeMovieClip();
}
}
}
}
updateAfterEvent();
}
stop();

davidprovost
4/6/2005 1:51:38 AM
Hey kglad, im trying to get it so that the car still rotates and stuff, but the
map will follow wereever the car is goin. Like the old GTA games when ur lookin
down on the car and the map always faces the same direction, it just moves with
the car. How would I get that?
kglad
4/6/2005 2:33:13 AM
if your car has instance name car_mc and the map has instance name map_mc, you
can use:

degtoRad = Math.PI/180;
speed = 0;
maxSpeed = 20;
ivar = 0;
car_mc.swapDepths(100000);
moveI = setInterval(moveF, 20, map_mc);
function moveF(mc) {
if (Key.isDown(Key.LEFT) && Math.abs(speed)>0) {
if (speed>15) {
ivar++;
rclip = mc.attachMovie("skids", "skid"+ivar, ivar);
rclip._rotation = car_mc._rotation;
rclip._x = car_mc._x-mc._x;
rclip._y = car_mc._y-mc._y;
}
car_mc._rotation -= 5;
}
if (Key.isDown(Key.RIGHT) && Math.abs(speed)>0) {
if (speed>15) {
ivar++;
rclip = mc.attachMovie("skids", "skid"+ivar, ivar);
rclip._rotation = car_mc._rotation;
rclip._x = car_mc._x-mc._x;
rclip._y = car_mc._y-mc._y;
}
car_mc._rotation += 5;
}
if (Key.isDown(Key.UP)) {
if (speed<=maxSpeed) {
speed = .9*speed+.1*maxSpeed;
}
} else if (Key.isDown(Key.DOWN)) {
if (speed>=-maxSpeed) {
speed = .9*speed-.1*maxSpeed;
}
} else if (Key.isDown(Key.SPACE)) {
speed = .7*speed;
if (speed>0) {
ivar++;
rclip = mc.attachMovie("skids", "skid"+ivar, ivar);
rclip._rotation = car_mc._rotation;
rclip._x = car_mc._x-mc._x;
rclip._y = car_mc._y-mc._y;
}
} else {
speed = .99*speed;
// set rate of slowing when coasting here
}
if (Math.abs(speed)<1) {
speed = 0;
}
mc._x -= speed*Math.cos(degtoRad*car_mc._rotation);
mc._y -= speed*Math.sin(degtoRad*car_mc._rotation);
if (ivar) {
for (jvar=0; jvar<=ivar; jvar++) {
if (mc["skid"+jvar]) {
mc["skid"+jvar]._alpha -= 5;
if (mc["skid"+jvar]._alpha<=0) {
mc["skid"+jvar].removeMovieClip();
}
}
}
}
updateAfterEvent();
}
stop();
davidprovost
4/6/2005 6:46:46 AM
kglad
4/6/2005 9:29:25 PM
AddThis Social Bookmark Button