GameMaker: Studio

GameMaker: Studio

View Stats:
AcroGames Jun 12, 2020 @ 4:14am
issues with collision detection
hey, so i wanted an enemy object to stop at collision with certain boundaries (obj_limit) inside which they normally wander, but ONLY when their var escape is false. if escape=true, I want them to be able to pass through the boundaries.
I ran into problems with the regular Collision event since the objects are (and need to be) marked Solid, so I use position_meeting() in Step event as a workaround.

what i'm trying here is that whenever an enemy bumps into the obj_limit, it would turn around if it is not in 'escape' mode and thus stay inside the limits.

if position_meeting(x,y,obj_limit){
if escape=false{
direction = image_angle+180
}
}

but it doesn't work, the enemy wanders through the limit nevertheless. also place_meeting() didn't help, well it does detect the collision, but not with just the sprite itself (basically obj_limit is a giant empty rectangle) but also its entire bounding box.

I just want that when obj_enemy collides with obj_limit, it would detect it and turn around in order to stay inside the obj_limit.
< >
Showing 1-4 of 4 comments
The Winter Bud Jun 12, 2020 @ 9:31am 
got a screenshot? That may help us understand what you want.
AcroGames Jun 12, 2020 @ 1:33pm 
found a sort of workaround. still, didnt manage to solve the problem how it originally was. annoying...!

basically, (Ill try and explain it more briefly:)

There are instances of 'obj_enemy,' which spawn inside an object 'obj_limit.' obj_limit is basically a big empty rectangle, with only the boundaries of the rectangle being the drawn parts of the sprite (and thus the Collision mask)
I want to, using other methods than Collision Event, make the enemy-objects stop or turn around when they collide with obj_limit (as in, its boundaries, so basically just obj_limit)

Somehow, place_meeting() and position_meeting() don't register any code that is supposed to affect the movement of obj_enemy's, like stopping them, turning them around etc. this never happens on collision.
Last edited by AcroGames; Jun 12, 2020 @ 1:33pm
The Winter Bud Jun 12, 2020 @ 5:31pm 
The main issue with what you want to do and using things like position_meeting() is that those functions apply to a bounding box.
When you use this you are checking a single point in the room for an instance or an object. This check will be done against the bounding box
using a direct collision method such as collision_point() will give you a better result

if(collision_point(x,y,obj_limit,true, false)){ if(escape=false){ direction = image_angle+180 } }
NOTE:
Collision point checks the point specified by the arguments x1,y1 for a collision with any instance of the object specified by the argument "obj". this check can be either precise or not, but for precise collisions to be enabled, the object or instance that you are checking for must also have precise collisions enabled for their sprite. If not, the default check is based on bounding boxes.
Last edited by The Winter Bud; Jun 12, 2020 @ 5:36pm
AcroGames Jun 13, 2020 @ 4:18am 
thank you!
i managed to solve the issue actually, using mp_potential_step for the enemy objects to avoid the limits when needed. but when they can pass through, they just ignore the avoid-code and get new values for speed and direction, allowing them to pass through the obj_limit.
I found your code useful as well, thanks for response
< >
Showing 1-4 of 4 comments
Per page: 1530 50