[F8] Perfecting car physics
I'm trying to perfect my car's physics and am running into a little bit of trouble.
1- Crashing into a bar - When the car crashes into a car at an angle, it looks as if it is bouncing off. If it hits it strait on or at an angle to quickly, it gets jammed into the bar and either goes through it very very slowly, or backs out of it very very slowly, either way you have to keep pressing the up/down key to get out.
2- Gears - I've already perfected this, the car has four gears, and when it hits each gear, how fast it accelerates changes. The cars don't have a max speed per say, but 4th gears acceleration is very low.
3- Braking - I'm still working on this one, I've got a very simple slow down, but I am still working on a drifting style brake, where if the car turnes too much durring brake, it starts spinning out/fishtails.
4- turning - perfected, I was going to add a drifting style of turning but said forget that. The turning point is on the frontwheel axis so backing up is realistic and turning isn't like in those kiddie games where it turnes from the center of the car (rofl).
5 - speed transfer - I'm a little confused on this one, I'm not sure how to transfer variables from one object to the next. I think it might be _root.varname.objectname but probably not, help would be nice there. I want to be able to have a speed transfer, so basically ({Ms * [(Mw - Cw)/Mw]} + {Cs * [(Cw - Mw)/Cw]})/2 = Ms
Ms is my speed, Cs is Crash speed (the other objects speed), Mw is my weight, Cw is Crash's weight (the other objects weight), and that is basically what it would be, if two different weighted objects crashed into eachother.
This formula would work both ways for being hit, and hitting the other, where the speeds basically transfer at an equal weight, or are altered if they are different before transfer.
If you can help, please give a a tip or send back altered source code.
Code:
onClipEvent (load) {
_rotation = 0;
var justhit = 0;
var rot:Number = 0;
var speed:Number = 0;
var maxSpeed:Number = 19;
var minSpeed:Number = -10;
var setSpeed:Number = maxSpeed;
var acc:Number = .3;
var setAcc:Number = acc;
var maxNos:Number = 500;
var nos:Number = maxNos;
var slow:Number = .98;
var brake:Number = .9;
var rev:Number = .2;
}
onClipEvent (enterFrame) {
_x += x;
_y += y;
rot = (speed/2);
_root.rotaters.text = rot;
_root.exp._x = 25;
_root.exp._y = 25;
if(this.hitTest(_root.ground) && speed > 1 || speed < -1){
speed = -speed/3;
}
if (Key.isDown(Key.RIGHT) && (speed != 0)) {
_rotation += rot;
speed -= .05
} else if (Key.isDown(Key.LEFT) && speed != 0) {
_rotation -= rot;
speed -= .05
}
if (Key.isDown(Key.SPACE)) {
speed *= brake;
if (speed < 1 && speed > -1){
speed = 0;
}
}
//©BoredPortal.com
if (Key.isDown(Key.UP) && speed < 19) {
speed += acc;
} else if (Key.isDown(Key.UP) && (speed < 25 && speed > 19)) {
speed += .05
} else if (Key.isDown(Key.UP) && (speed > 25)) {
speed += .01
} else if (Key.isDown(Key.DOWN) && (speed<1)) {
speed -= rev;
} else if (Key.isDown(Key.DOWN) && (speed>=1)) {
speed *= brake;
} else {
speed *= slow;
}
if (speed>50) {
speed = 50;
}
if (speed<minSpeed) {
speed = minSpeed;
}
x = Math.sin(_rotation*(Math.PI/180))*speed;
y = Math.cos(_rotation*(Math.PI/180))*-speed;
}
This is MY code, don't take it and use what I made without consent from me and without giving credit where credit is due.