0 votes

When the player is in range for the enemy to attack, the enemy launches to the player. This is done using a tween. The problem is that when I have multiple enemies, all attacking at the same time, they all go into eachother and then when the tween is finished they are pushed out of eachother. Is it possible to make it so that the tween still plays when the player is in attack-range, but it still detects collision and doesn't force the enemy through each other?

Godot version 3.3 stable
in Engine by (69 points)

You're asking two systems (physics and tweens) to interact in some way; they're going to conflict. Rather:

  • Consider checking for collisions before 'tweening' and avoid dashing (e.g. a raycast?).
  • Layer enemies so they don't interact with each other.
  • Allow the tween to run in physics time; this may make the enemies behave different if you've physics based code.

The first probably makes more sense and will look more pleasing (e.g. the enemies appear smart) depending on your use case.

The first two options aren't viable for me because I still want the enemies to collide with eachother and make them able to attack at the same time. I should make it clearer what it is I wan't to achieve: I wan't it so that the tween plays the attack as normal except that it shouldn't ignore the colliders I have set and force the attacking enemies through eachothers respective colliders. So basically, I want it so that if multiple enemies attack the player at the same time, then they should push eachother away, instead of moving inside eachother. I will try to film this and post it here.

As for:

Allow the tween to run in physics time

Im still a beginner and didn't really understand this. Do you mean playing the tween in the physicsprocess() function? Because Im already doing that.

A tween has a TweenProcessMode property that can run in idle or the physics step. This may allow the colliders to respond although really, you should move the enemies without tweening to allow them to collide correctly. I’m unsure which properties you’re tweening but it’s likely just setting then so physics won’t ‘see’ the changes, if that makes sense.

…and to clarify the raycast suggestion. You could apply a force to any colliding enemies so they are shunted out of the way along the direction’s tangent (+/-).

In fact, you could just apply an exploding force at some point along the attack vector (or each step of the tween) to push other enemies aside.

Doesn't work. The tween is basically unstoppable and will force it's way through any collider or added force.

Also, here is the video demonstration.

As you can see, if multiple enemies attack at the same time they all go into eachother and when the tween finishes they get pushed out of eachother. This looks weird and as a result of this I also got that weird glitch at the end of the video.

Please log in or register to answer this question.

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 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 webmaster@godotengine.org with your username.