(SOLVED) How do I stop Player movement in certain direction when collide?

M

MooMoo

Guest
I have been making a game in gamemaker studio 2 and I can get the game to recognize a collision but I couldn't figure out how to make it stop the player without making them stuck next to the wall
 
W

waturi

Guest
are both the player object and object its colliding with set to solid?
 
W

waturi

Guest
try setting them to solid. when two solid objects collide, GM should trigger the collision event when they are actually one pixel apart so the collision boxes dont end up overlapping and getting them stuck.
 
M

MooMoo

Guest
  • thats not my problem my problem is trying to figure out how to stop the player without freezing him
 
W

waturi

Guest
I assume setting them to solid didn't work then?

what does your collision event code look like?
 
M

MooMoo

Guest
I currently only have a if(place_meeting(x,y,obj_wall)) in place right now
 
W

waturi

Guest
next line should be set horizontal speed (or vertical speed, or both if it's top down) to 0. Should stop player object from moving. is that not working?
 
M

MooMoo

Guest
I was using the drag and drop speed stuff... Should I change that out?
 
W

waturi

Guest
no, it should work with DD.
In your player object, set a collision event with the wall. In that event, drag the set speed function (the blue icon with the three arrows) and make sure it is set to Horizontal with a value of 0. If you need to change the vertical speed drag another set speed and set it to Vertical 0. Then in the object properties for both, make sure the "Solid" box is checked.

player should stop moving when encountering the wall, but then resume moving when another direction key is pressed
 
M

MooMoo

Guest
I just tried that but when I got near the wall I got stuck and couldn't escape
 

KurtBlissZ

Member
Basic concept for collisions, check whether the next position is free then move there.
Idk how you do that in drag and drop exactly though ;p

in gml it be like this

Code:
if not place_meeting(x+4, y, obj_wall) x += 4;
 
S

SpaceDragonForce909

Guest
Okay, I've got 2 objects, one is an enemy killzone under the viewport and the other is a zone (just an object with an invisible sprite set to cover the whole length of the view) and when both collide I want it to stop the player (which by itself moves up as my game is a vertical shmup) , the viewport and a camera (a sprite-less object that I'm using for the clamping, not an actual camera).
 
Top