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();
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();
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();
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();
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...
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();
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?
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();
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 {
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();
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?
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();
Don't see what you're looking for? Try a search.
|