• 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!

Legacy GM mouse movement collision issue

A

Amazing creature

Guest
The player is controlled with the mouse, if it collides with a wall it stops like it should, but then I cant move it for some reason, it stays stuck.

obj_mouse:
step
Code:
x = mouse_x
y = mouse_y
obj_player
step
Code:
if x < obj_mouse.x
{
   if !place_meeting(x-1,y,obj_solid)
   {
   x += 10
   }
}
if x > obj_mouse.x
{
   if !place_meeting(x+1,y,obj_solid)
   {
   show_debug_message("it works")
   x -= 10
   }
}
 

Simon Gust

Member
The player is controlled with the mouse, if it collides with a wall it stops like it should, but then I cant move it for some reason, it stays stuck.

obj_mouse:
step
Code:
x = mouse_x
y = mouse_y
obj_player
step
Code:
if x < obj_mouse.x
{
   if !place_meeting(x-1,y,obj_solid)
   {
   x += 10
   }
}
if x > obj_mouse.x
{
   if !place_meeting(x+1,y,obj_solid)
   {
   show_debug_message("it works")
   x -= 10
   }
}
Do you know how the code you've written works?
If you move 10 pixels a step, you should also check ahead 10 pixels and also in the direction of movement.
Code:
if x < obj_mouse.x
{
   if !place_meeting(x+10,y,obj_solid)
   {
   x += 10
   }
}
if x > obj_mouse.x
{
   if !place_meeting(x-10,y,obj_solid)
   {
   show_debug_message("it works")
   x -= 10
   }
}
This is the unsmoothed version.
 
Top