Legacy GM [SOLVED] TDS solid walls slide collisions

E

eddx

Guest
Hello! I new to game maker and programming at all, so i need some help with modify my collision code.
  • I already wrote some code to stop player if he contact with solid walls, but i need some sliding by angled walls.
  • obj_Player are controlled by WSAD through some accelerating/friction code, and finally it has some hspeed and vspeed. So i dont want to interfere collisions between WSAD controlls and hspeed,vspeed
  • I can't figure out how to modify direction-based movement to my hspeed/vspeed-based movement
  • Please help me to adapt DONOR CODE to work with hspeed, vspeed, direction and solid objects
  • i need the collision system completely independent of controls
MY COLLISION CODE which using hspeed and vspeed
Code:
///Player Collision

if hspeed != 0
if !place_free(x + hspeed, y)
{
 if hspeed > 0 move_contact_solid(0,hspeed)
 if hspeed < 0 move_contact_solid(180,-hspeed)
 hspeed = 0
}

///////
if vspeed != 0
if !place_free(x + hspeed, y + vspeed)
{
 if vspeed > 0 move_contact_solid(270,vspeed)
 if vspeed < 0 move_contact_solid(90,-vspeed)
 vspeed = 0
}


DONOR SLIDE CODE
Code:
var spd, dir, angle, angle_step, lx, ly, i;
spd = 8;
dir = -1;
angle = 90;
angle_step = 5;

if keyboard_check(ord('W')) dir = 90;
if keyboard_check(ord('A')) dir = 180;
if keyboard_check(ord('S')) dir = 270;
if keyboard_check(ord('D')) dir = 0;

if dir != -1
{
   for (i = 0; i < angle; i += angle_step)
   {
       lx = lengthdir_x(spd, dir + i);
       ly = lengthdir_y(spd, dir + i);
       if place_free(x + lx, y + ly)
       {
           x += lx;
           y += ly;
           break;
       }
   
       lx = lengthdir_x(spd, dir - i);
       ly = lengthdir_y(spd, dir - i);
       if place_free(x + lx, y + ly)
       {
           x += lx;
           y += ly;
           break;
       }
   }
}
 
Last edited by a moderator:
Top