scrCollision:
//script for collisions with other cars (note: doesn't work with buildings well at all)
//created by Bravesaturn
dirToOther = point_direction(x,y,other.x,other.y)+(360-lDirection); //find relative direction to other (0 degrees always equals the direction the car is facing)
dirToOther = scrFix360(dirToOther); //make sure the angle's under 360
dirDiff = 45-abs(45-scrFind45(dirToOther)); //find how far away the reference angle is from 45 degrees
spinAmt = cos(degtorad(dirDiff))*sin(degtorad(dirDiff)); //get how much to spin (maximum 0.5 at 45 degrees)
spinDif = spinAmt/2*other.speed+4; //the 4s are arbitrary; change them as you wnat
if (dirToOther < 90) //is hit in the first quadrant
{
lDirection -= spinDif; //rotate clockwise
}
else if (dirToOther < 180) //is hit in the second quadrant
{
lDirection += spinDif; //rotate counter-clockwise
}
else if (dirToOther < 270) //third quadrant
{
lDirection -= spinDif; //rotate clockwise
}
else //fourth quadrant
{
lDirection += spinDif; //rotate counter-clockwise
}
speed /= 1.1; //slow down a little (feel free to change this number)
lY += other.speed/1.5; //move in the new direction a little
motion_add(point_direction(x,y,other.x,other.y)-180,other.speed/3.5); //now move a little in the opposide direction (change the 3.5 to whatever you need)scrFind45:
//reduces the angle until it is less than 90 (finds reference angle) var angle; angle = argument0; while (angle> 90) angle-= 45; return angle;
scrFix360:
//keeps the angle between 0 and 360 var angle; angle = argument0; while (angle> 360) angle-= 360; while (angle< 0) angle+= 360; return angle;
Then just simply execute the scrCollision script in the collision event between the cars. Make sure you spell the scrFind45 and scrFix360 scripts right.











