• Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

Question - GML Visual A little advice on collision shapes in drag and drop project

B

bluepill

Guest
Hi, I have a little test project where I'm trying out ways to stop my player sprite from leaving the play area. I have this bit of drag and drop:
collision test.PNG

The player moves to the left when the left arrow key is pressed. What this is trying to do is stop them moving to the left when the collision shape (rectangle) is hit.

What happens when I run this is the player keeps moving to the left. I added the debug message to try and see what was going on and it doesn't get displayed; so there is something wrong with how I did this or my understanding of what "if collision shape" does. Also, this is the only place in the code where the player is moved to the left and there is a collision mask for the player that works when colliding with other objects in the project.

If anyone has an idea of what I've done wrong (I assume it's something really simple) I'd appreciate some help.

Thanks
 

gnysek

Member
I am not sure, since I didn't used drag'n'drop in GMS2, but else should be on right of this block.

Or select "not" and put move action on right of rectangle collision block.
 
B

bluepill

Guest
Thanks for the advice. I managed to double check the if ... then ... else ... construction and it is correct. I also managed to get the player to stop moving when it collides with the rectangle. The weird thing about it is that I can only get it to work when I put the code in an object that isn't the player; and then use the Applies To feature to affect the player's position. If I put the code in the Key Down or End Step event it just doesn't work.
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Try changing the "obj_player" to the built-in variable "id". This will make the code look for the actual player instance rather than the player object. To be honest I can't see why that code you have wouldn't work "as is" and want to test different things to see what the issue could be. It could be a bug...
 
B

bluepill

Guest
Thanks for the help @Nocturne

This works to stop the player when they collide with the left edge; note that obj_player is doing a JumpToPoint on the Key Down - Left event for this test.
collision test 2.PNG

This doesn't work (either with id or obj_player) note; there's only 1 instance of obj_player
collision test 3.PNG

I figure that I must be doing something in the wrong order or the wrong way.
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Okay, the good news is that your actions are fine and you are not doing something wrong.... :)

The bad news is that the action is bugged if you try to use it to check an instance is colliding with itself. :(

Basically, the collision shape action works using the collision_ GML functions, and those functions have an argument "notme" which if set to tru means that any collision checks will NOT detect the instance calling them. This is true by default for the DnD (and you have no way to change it currently), so when you have the player try to check for a collision it's not working as the underlying function is saying "don't check this instance". So, either call the function from another instance OR take that whole event anbd convert it into GML, then set the "notme" argument to false.

Sorry for this, but at least you've flagged an issue we weren't aware of and I've filed a bug to get it corrected.
 
B

bluepill

Guest
That's great news. I don't mind finding bugs; that's what a beta version is for after all.

I'm just a bit nervous sometimes when I post and it seems like a really, really simple thing.
 
Top