Collisions with solids: pushing on opposite direction and speed modification

Axl Trauts

Member
Hi,

I'm having a bit of difficulty here. Before I start making a lot of conditionals in order the player moves I want to ask.

In one of its forms, the player is a plane with an engine flame object in the tail that follows it. This is because if the player keeps moving left or right, the last frame of the left or right sprite will stop until the player releases the button.
So, in the Step Event, the player has a speed modifier that goes like this

Step Event
GML:
hspd = 0;
vspd = 0;
if y > camera_get_view_y(view_camera[0])
// if y > __view_get( e__VW.YView, 0 )+40
{   vspd = -6;  }       // Moves out of the view when it reaches the top
if camera_get_view_y(view_camera[0]) == 0
//if __view_get( e__VW.YView, 0 ) == 0
{   vspd = 0;   }

if playerdefeat == 0 // an automatic animation occurs when the player respawns
{    if keyboard_check(vk_left)
    {   if x > 40 then hspd -= (6+spdmod);  }
    if keyboard_check(vk_right)
    {   if x < room_width -40 then hspd += (6+spdmod);  }
    if keyboard_check(vk_up)
    {   if y > camera_get_view_y(view_camera[0]) + 40 then vspd -= (6+spdmod);  }
    if keyboard_check(vk_down)
    {   if y < camera_get_view_y(view_camera[0]) + 640 then vspd += (6+spdmod);  }
}
x = x + hspd;    y = y + vspd;
The flame object has the Step Event:
x = obj_plane.x;
y = obj_plane.y;

But when the player collides with a solid object, the flame moves as the x+hspd and y+vspd position even if the player remains still.
Of course I can add a if player collides with a solid object condition but I would need to move all solids to a single parent? I already have some of these object as Enemy Parents.

Another thing: When colliding a solid I'd like the object to be pushed a bit on the opposite direction. I did this but I don't feel is clean enough (too many new variables). The effect seems to eliminate the flame misplacement, but I know it's still there.

Step Event
GML:
if place_meeting(x,y,obj_volcan_1) && inmovil == 0
{    inmovil = 1;
    var pd = point_direction(x,y,obj_volcan_1.x,obj_volcan_1.y) + 180;
    xx = floor(x+lengthdir_x(24,pd));
    yy = floor(y+lengthdir_y(24,pd));
}
if inmovil == 1
{    mp_linear_step(xx,yy,6,false);
}
if (inmovil = 1 && x == xx && y == yy)
{ inmovil = 0;    }
Inmovil is a immobile flag, to keep the player move until it's pushed away the full distance.

EDIT: Removed the +hspd and +vspd on place_meting as it made the solid volcano object had an invisible force field :D
 
Last edited:
Top