H
healthyaddiction
Guest
So I used the Shaun Spalding tutorial on swinging a sword and checking collision with an enemy and created some code that looks like this:
This works perfectly for hitting one enemy instance, but I want the sword to hit multiple enemies if they're close enough and this doesn't do that.
I looked online and found someone who advised to use distance instead of collision, so I made this:
This does allow me to hit multiple enemies but a) doesn't seem to detect the hit as consistently and b) I can hit enemies stood behind me (because they're still within range).
Could anyone advise me on what is the best solution to this? Ideally I'd like to use the top version as the collision detection seems to be more consistent than the distance detection. But if the second is needed to be used a tweak to fix my problems would be greatly appreciated.
Kind Regards
Code:
if ((image_index >= 1) && (image_index <=3)) {
with (instance_create(x,y,obj_skitter_hitbox)) {
image_xscale = other.image_xscale;
with (instance_place(x,y,obj_Robot)) {
if (hit == 0) {
hit = 1;
state = enemy_hurt_state;
}
}
}
}
I looked online and found someone who advised to use distance instead of collision, so I made this:
Code:
if ((image_index >= 1) && (image_index <=3)) {
with (instance_create(x,y,obj_skitter_hitbox)) {
image_xscale = other.image_xscale;
with(obj_Robot) {
if (point_distance(x,y,other.x,other.y) < 70) {
if (hit == 0) {
hit = 1;
state = enemy_hurt_state;
}
}
}
}
}
Could anyone advise me on what is the best solution to this? Ideally I'd like to use the top version as the collision detection seems to be more consistent than the distance detection. But if the second is needed to be used a tweak to fix my problems would be greatly appreciated.
Kind Regards