I have the following object types:
- oWall
- oEnemy
And I'm trying to call the new move_and_collide function in such a way that it would collide against both of them. Something along the lines of:
objectsToCollide = array_push(array_create(0), oWall, oEnemy);
move_and_collide(xSpeed, ySpeed, objectsToCollide);
I know that a viable solution is the make a new parent object that oWall and oEnemy could inherit from, but I'm hoping to avoid that since it would add unnecessary entities in my code.
First,
array_pushdoesn't return anything and you don't have to use it like that either - you can do the following (manual):The other thing is that
move_and_collidedoes not support being given an array of objects to check against, at least not as of writing this.You could implement it yourself (you can see how the built-in function works here - it's just math and calls to
instance_place) and make eachinstance_placecall a loop over the array of instances instead, or consider whether you needmove_and_collidefor enemies - perhaps you could move against walls and then revert to previous position if it turns out that the player has ran into an enemy.And if you can straight up stand on an enemy, making it a child of oWall sounds reasonable enough.