GMS 2 Collisions with 2 objects created with instance_create

S

Spencer S

Guest
I have hurtbox and hitbox objects that are created around enemies and the player in my game, using instance_create_depth(). And that's fine, for the most part, except that when a hitbox is created, I need some way of registering a collision with the hitbox, and the hurtbox (like a collision event), both created with instance_create_depth(). How would I do this?

I could use place_meeting, but doesn't that take a lot of RAM, over time? I'm looking for some way of initiating a collision event with two objects that are created using instance_create_depth(), and I'd rather it be less expensive than functions like place_meeting.

EDIT:
I just thought of assigning the instance_create_depth() hitbox objects a parent object through code, and then, in that parent object's Collision Event, including code for collisions. Would this work? What if the hitbox object created by instance_create_depth() hits multiple hurtboxes? Is there a way to register multiple collisions with the same type of object in one step in a parent's Collision Event?
 
Last edited by a moderator:
I have hurtbox and hitbox objects that are created around enemies and the player in my game, using instance_create_depth(). And that's fine, for the most part, except that when a hitbox is created, I need some way of registering a collision with the hitbox, and the hurtbox (like a collision event), both created with instance_create_depth(). How would I do this?

I could use place_meeting, but doesn't that take a lot of RAM, over time? I'm looking for some way of initiating a collision event with two objects that are created using instance_create_depth(), and I'd rather it be less expensive than functions like place_meeting.
I would not worry about place_meeting being expensive, especially not in terms of ram.

Also using objects as your hurtbox or hit box sets you up so you have to use place_meeting or instance_place. They're generally never a problem unless you have enormous and percise hitboxes, other than that, use them to your liking.

As for how you want to set it up, I think you should do this.
When you create your hurtbox, always make a variable that has the id of the enemy or player that it belongs to. So instead of just using
instance_create_depth
Instead Use

with instance_create_depth {
owner_id = other
}

This will make it so that the enemy or player that makes the hurtbox also has it's id saved in the hurtbox.

Then in the hitbox, I recommend you check collision with instance_place because it is more flexible, but you can use a collision event if you want like this

var _target = other.owner_id:
_target.hp -= 10

Or using instance_place in the step event like this

var _hurtbox = instance_place(x,y,obj_hurtbox)
if _hurtbox != noone {
var _target = _hurtbox.owner_id
_target.hp -= 10
}

Or whatever u want to do when they collide. The step event method is a little bit more code, but it is much nicer to handle in the long run.
 
Top