GameMaker collision function instance_position()

L

lord_berto

Guest
how does game maker handle the collision function instance_position()?

all my game objects have a parent called obj_solid ( including players and walls etc )

im trying to code a function to allow anything to push against each other.

in the step event of object A i have :
if instance_position(x,y,obj_solid)
{
/// code for pushing/moving out of way occurs
}

but what if there are multiple instances touching object A? which object does game maker ultimately
choose as input for instance_position collision check?
 

FrostyCat

Redemption Seeker
There's no telling which one it is, but you will get one of them.

In your situation, if you want the actual instance ID, you should save it in a variable first. And if you intend to check for a mask-mask collision instead of a point-mask collision, you should have used instance_place() instead.
Code:
var inst_solid = instance_place(x, y, obj_solid);
if (inst_solid != noone) {
  // Move out of inst_solid's way
}
I strongly recommend that you read up on the difference between collision functions. And if there are things like obj_solid.x or with (obj_solid) where the comment is, you also need to read up on the difference between objects and instances.
 

TheouAegis

Member
instance_position() doesn't check "collisions". The calling instance can be returned as well, which is not usually what one wants in a collision check.
 

Mert

Member
Maybe consider using physics engine in which you don't even have to write any code for achieving this action.
 
Top