# Realistic Car Collisions Using Boosted32's Engine

8 replies to this topic

### #1 Bravesaturn

Bravesaturn

GMC Member

• New Member
• 448 posts

Posted 07 April 2004 - 12:25 AM

I've been working off and on with trying to make accurate collisions between two cars using Boosted32's engine, and I'm finally done. The cars in this will rotate realistically - hit them in the front drivers side and they'll spin clockwise. Hit them directly in the side and they won't spin much at all. Here are the scripts... Enjoy!

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
}
{
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.
• 0

### #2 Razon

Razon

GMC Member

• GMC Member
• 268 posts
• Version:GM:Studio

Posted 07 April 2004 - 01:49 AM

wow good collisions umm it was made with the worse of the 2 that were posted by him? darn
• 0

### #3 Hyun

Hyun

Pixel Fiend

• New Member
• 27 posts

Posted 09 April 2004 - 09:04 PM

Wahey! Someone has managed to create realistic car collisions! Hats off to bravesaturn and Boosted for making this engine! I think you can start to introduce ragdoll effects on other objects, since you have managed to do this!
• 0

### #4 Bravesaturn

Bravesaturn

GMC Member

• New Member
• 448 posts

Posted 11 April 2004 - 01:37 PM

Hehe thanks. I've been working on ragdoll physics using this approach (finding the angle to the other and basing if off of that). Although right now I'm working on making more accurate wall collisions, which you would think would be easier. I'll probably just update this topic when I finish.

• 0

### #5 Pokid

Pokid

GMC Member

• New Member
• 15 posts

Posted 11 April 2004 - 05:13 PM

This is great! May I sugest mabe, making the other cars move?
• 0

### #6 Bravesaturn

Bravesaturn

GMC Member

• New Member
• 448 posts

Posted 12 April 2004 - 10:05 PM

Certainly. Check it out now - it has a car that moves from node to node (rather quickly I might say). You'll need to edit it a bit to make it work for multiple cars, but it's mainly done to show how to make the cars go to a certain point even after being hit.
• 0

### #7 Miguel sanchez

Miguel sanchez

GMC Member

• New Member
• 3 posts

Posted 13 April 2004 - 12:20 PM

this is like the coolest thing ive ever seen in gm but 1 little thing that probly doesent even matter - you cant hold down space and go left at the same time but you can go right - strange
• 0

### #8 rjbruin

rjbruin

Programmer

• New Member
• 302 posts

Posted 24 December 2006 - 07:42 AM

Can you please make a gm6 version of this??? I'd like to use this in my game...
• 0

### #9 cj sniper 98

cj sniper 98

GMC Member

• GMC Member
• 96 posts
• Version:GM8

Posted 01 September 2012 - 09:52 PM

hmmm, BraveSaturn can you give me the link of boosted32 car engine, because I downloaded the gm6 version of this engine from your website, and I didn't understand it because you use some vector objects in scrCarStep script, anyway please give me boosted32 engine.
• 0
Press , if I helped you, I really need that