Top Down Car Collision help!

S

sabrosito

Guest
Hi there! i just joined the forum cause ive been wrecking my head over this. So i'm making a top down Car Combat game similar to Twisted Metal on PS1 or the battle mode of Super Mario Kart. I made a 2D top down lil engine that so far only has rotation and drifitng i learned here in the forums. Now what im trying to see is how to implement a knock back collision where if the player bumps the walls he bounces off a bit . Close to the collision in Super Mario Kart. Im planning on having 45 degree angles so the courses curve more naturally when i translate to a mode 7 ish 3D .

ive experimented with many collisions i found on threads but i cant seem to find what im looking for in google. maybe im googling it wrong, or maybe im not sure how to word it the most basic way to a search engine. im using the classic shaun spalding method cause im avoiding physics since im not really into the in engine functions of them. also avoiding to use solids.
highly appreaciate if someone could give me advice, since so far , all my car does is jump positions and freak out when i get near a wall.

eventually i want to program in more players and enemies that i want them to bump with each other and not get stuck with themselves or stick each other in walls. i hope this is descriptive enough to understand my problem.


var gas = keyboard_check(vk_up) - keyboard_check(vk_down)
if(gas!=0) // pressing one of dirs
spd+=accel*gas
else
{
spd=lerp(spd, 0,.05); //slows down car to a stop
}
if keyboard_check(vk_left)
{if spd<0 then angle+=-(tspd+drift) else angle+=+(tspd+drift) }


if keyboard_check(vk_right)
{if spd<0 then angle+=+(tspd+drift) else angle+=-(tspd+drift) } //change angles

direction = dir;
speed = spd;
image_angle = angle;


if spd>0tspd=spd/.80+(maxspeed-(spd/2))/2 else {tspd=4 drift=0}
if spd>maxspeed then spd=maxspeed
if spd<-maxspeed/2 then spd=-maxspeed/2
if drift>0 then drift+=-0.5
if keyboard_check(vk_space) then {spd+=-(speed/40) if drift<2 then drift+=+1}
dir+= median(-tspd, tspd, (((((angle-180) - dir) mod 360) + 540) mod 360) - 180) //drift
if (angle >= 360){
angle -= 360;
}
if (angle < 0){
angle += 360;
} //limits angle



//collision

hspd=lengthdir_x(spd,dir);
vspd=lengthdir_y(spd,dir);
if(place_meeting(x+hspd, y, oWall)) /// am i approaching tis right?
{
while(!place_meeting(x+sign(hspd), y, oWall))
{
x+=sign(hspd);
}
hspd=0;
spd = -spd/2; // i want it so the player slows down everytime he bumps the wall.
}
x+=hspd
if(place_meeting(x, y+vspd, oWall))
{
while(!place_meeting(x, y+sign(vspd), oWall))
{
y+=sign(vspd);
}
vspd=0;
spd = -spd/2;
}
y+=vspd
 
Top