0 votes

Hi so when I punch or kick. The NPC standing behind's hitbox gets activated too. I was wondering if this could be stopped.
The pictures will explain what I mean.enter image description hereenter image description here

If this can't be helped. Do you think it'll ruin the game? I have noticed this happening in some professional games too.

Godot version 3.3.1
in Engine by (203 points)

2 Answers

+1 vote

Use collision layers. Refer to the documentation here.

by (1,375 points)

Thanks. I know about that but that won't help here unfortunately.

+1 vote

I think one way you could do that is to deactivate the hitbox the moment your character hits an enemy so that the next enemy doesn't get hit, of course you'll have to activate the hitbox again everytime you have to hit (with an AnimationPlayer for example), I'm not too much into GDScript but the function of your hitbox signal should look like something like this:

func on_hit(body):
   if(body is enemy):
      hitbox.CollisionShape.disabled = true
by (254 points)

Yea that's a good solution. I was thinking something similar.
There are problems to this as sometimes the NPC standing behind gets hurt first with long range attacks like spears and stuff.
The second problem is that hit box activation and deactivation was done with animation player. Which was much simpler. It can be done with script too though.

I'm going to put off this issue for later. Do you think it'll make the game bad? I've noticed this happening with studio made games as well. And 3D games too. I'm wondering if this is something I even need to fix as it won't be noticeable a lot in the game.

For long-range attacks you can tweak the hitbox so it only hits the enemy in front of you, a hitbox isn't obliged to cover the whole weapon or put it on a tip so just keep working on it until you find a satisfying result.
You can mix hitbox deactivation with a script and an animation player.
Personally, I don't think it's going to make the game bad neither should you really think about it as long as it's not too broken, if studio games get away with it why not you?

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.