MartinK12
Member
Game with a lot of bullets and enemies, ie. platformer, bullet hell, etc. When player gets hit he has immunity for 2 sec. Where is better to put collision checks between player and enemies plus bullets? I do those checks in end step.
1. If put those checks inside enemies and bullets then each object need to perform collision check but code is very easy, light and clear. We have bunch of objects doing unnecessary collision checks but it’s enough for them to use just place_meeting (which is faster) although in this case we might even do pixel precise collision check (we only need to check speeds of one obj_player).
2. If inside player than we need to use instance_place_list to check all enemies and bullets we might collide at the same time so we have one heavy object player which constantly needs to create this list and then perform heavy calculations between those object (damage priority, immunity, send data back to each colliding object, etc.). obj_player is already heavy by plenty other things. Impossible to do pixel perfect collision check from inside player (too many objects with too many different speeds). But only one object player do collision check and with only a handful number of objects at the same time.
So which one is better? I did both but I’ve no experience so I don’t know which one will be better performance wise. Looks like maintenance is waaaaay easier inside enemies and bullets.
3. BTW performance wise – I’m curious is it worth to use place_meeting before instance_place when we need to get id of object we collide with? Example:
Thank you for all your thoughts and shared experience
1. If put those checks inside enemies and bullets then each object need to perform collision check but code is very easy, light and clear. We have bunch of objects doing unnecessary collision checks but it’s enough for them to use just place_meeting (which is faster) although in this case we might even do pixel precise collision check (we only need to check speeds of one obj_player).
2. If inside player than we need to use instance_place_list to check all enemies and bullets we might collide at the same time so we have one heavy object player which constantly needs to create this list and then perform heavy calculations between those object (damage priority, immunity, send data back to each colliding object, etc.). obj_player is already heavy by plenty other things. Impossible to do pixel perfect collision check from inside player (too many objects with too many different speeds). But only one object player do collision check and with only a handful number of objects at the same time.
So which one is better? I did both but I’ve no experience so I don’t know which one will be better performance wise. Looks like maintenance is waaaaay easier inside enemies and bullets.
3. BTW performance wise – I’m curious is it worth to use place_meeting before instance_place when we need to get id of object we collide with? Example:
GML:
if place_meeting(x, y, obj_to_check) {
var object_we_colide_with = instance_place(x, y, obj_to_check);
//do some stuff to object_we_colide_with...
}