Okay, so I’m having trouble with some making a somewhat of a swarm of enemies encircling a player. The biggest problem is clumping.
- I can’t use Pathfinding to make sure they don’t bump into each other once they enter the encircled raidus
- Moving them away from each other via walking is jittery and unusable.
Right now I’m considering:
- Using BodyForces that update continuously to push the NPCs away from one another until they’re a specific distance apart as they walk towards a position
- Calculate a new position to move to in regards to the player’s position and the surrounding NPCs
The second option seems a lot more predictable, except I don’t know where to start with this because I have no idea what I’m doing with vectors.
Here’s the article I found about battle circle AI that I’m trying to replicate but am having trouble doing. Any assistance would be much appreciated
also check out astral:hearts, the project where i’d be using this
5 Likes
First thing first, this has to be in relation to a primary humanoid. Let’s call this one A.
A bumps into, or gets too close to, another humanoid of which we name B.
First in the chain of events is the direction. We have to get the direction A will be moved by the body force:
local dir = (A.HumanoidRootPart.Position - B.HumanoidRootPart.Position).Unit
Next create your body force and then plug this dir variable as the force. Remember that a body force also takes mass into consideration so please multiply the dir value as necessary to produce a desired effect.
The direction points away from humanoid B so that will push the humanoid A away.
3 Likes
This is a super late reply, but would this also work if I were to calculate the resulting positions instead? As in I would add the unit vector scaled by, say the radius of the humanoid, to get a new position instead of using BodyForce objects?
A new position?
Well, you could use the same unit vector, simply take the HumanoidRootPart.Position and add the Unit Vector multiplied by the radius. This will result in a new position with accordance to the radius necessary.
local dir = (A.HumanoidRootPart.Position - B.HumanoidRootPart.Position).Unit
local nPos = A.HumanoidRootPart.Position + (dir * Radius)
A:MoveTo(nPos)
If you have any errors or weird positional errors try to set the humanoid root part as the Model PrimaryPart
2 Likes