• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GML How to find the nearest no collision point?

E

Edwin

Guest
For example I have a big object and a small object. When the small object collides with the big object, small object needs to find the nearest position where it's not colliding with the big object.

I need this because if the player get stucked in the wall, he need to unstuck but not simply moving at random direction. Instead of this, he needs to move at direction that is nearest to him.
 
Not sure exactly what you are looking for here. Possibly you what the big object to push the small object around? If so...
Code:
//collision event//
var power=1
x-= lengthdir_x(power,point_direction(x,y,other.x,other.y))
y-= lengthdir_y(power,point_direction(x,y,other.x,other.y))
 

Bentley

Member
If you're trying to move out of the collision and then move to the point before the collision:

obj_small
[Collision event with obj_big]

// Backtrack to previous position
x = xprevious;
y = yprevious;

// Move forward until you're next to the big instance
var dx = lengthdir_x(1, direction);
var dy = lengthdir_y(1, direction);
while (!place_meeting(x + dx, y + dy, obj_big))
{
x += dx;
y += dy;
}
 
Top