On this site, you get more insight on how to set up agent formations in combination with Waypoints.
Setting up Formations
In order to set up a formation you need a couple of VH in the scene that shall walk together in formation. You only need to set up one VH that will serve as the parent of the group.
In the details panel of the parent VH select the VHMovement component. Under the header Group Movement you can see three parameters:
Parameter | Details |
---|---|
Child VH | A Map containing a VH actor as key and a float that represents the offset from the current VH as value. |
Group Formation | Currently only 2 formations are supported. Walking in line and abreast. |
Draw Debug Spheres | Show navigation points used by the children. See How it works |
For every VH that should be part of the formation, provide an entry in the Child VH Map of the parent. As key provide a VH actor and as value an offset that specifies the distance the child will have from the parent. Depending on the selected formation the offset will change its behavior. E.g. if you select InLine a positive offset will be behind the parent and a negative offset will be in front of the parent. If you select Abreast a positive offset will be to the left of the parent and a negative to the right.
Don't forget to set up the Waypoint Movement (selecting a Waypoint Group and order). You only need to set up the parent, as all settings (Waypoint and Group Movement) will be forwarded to the children (all VHs specified in the Child VH Map) when the game starts.
An example implementation can be found on the GroupMovementTest Map.
How it works
The parent will simply traverse all the Waypoints, but for the children we need to create additional points for navigation. If you enable DrawDebugSpheres you will see additional points that are calculated for every child around every Waypoint, depending on last and next Waypoint, group formation and offset.
Abreast
For abreast formations and also arbitrary formations in the future, we have to differentiate between a child on the outside and inside path.
1. Outside Path
If a child is on the outside path the algorithm creates the following points, that the child will traverse in the following order for every Waypoint:
Parameter | Details |
---|---|
SpeedUpPoint | On the outside path the child needs to walk a greater distance than the parent, therefore we introduce a point at which the child starts to walk faster than the parent. The walking speed is raised accordingly, so that the child arrives at FirstPointOfNextPath at the same time the parent arrives at the Waypoint. This value is however bound to only be a certain amount higher than the parents walking speed to prevent big jumps in speed. |
LastPointOfCurrentPath | Last point in the current walking direction |
IntermediatePoint | Additional point to make walking path smoother for big angles |
FirstPointOfNextPath | Last point that is calculated for the current Waypoint. This point "points" towards the next Waypoint and is therefore the first point of the path towards the next Waypoint |
2. Inside Path
On the inside path the Algorithm just creates the LastPointOfCurrentPath and adjusts the walking speed such that the child arrives there at the same time the parent arrives at the Waypoint.
Big angles
If the angle from the last Waypoint towards the next Waypoint is very large (close to 180 degree), the children will change sides. So instead of walking around the waypoint to stay on the e.g. left side of the parent (in walking direction), the child will just turn around and be then on the right side of the parent (in walking direction).
In general the movement of children is always triggered by the parent. In combination with walking speed adjustment, it is guaranteed that the formation is always maintained. It can for example happen, that a child on the outside path cannot reach the last point on its current walking path, which would be FistPointOfNextPath, due to movement speed restrictions (speed is restricted because it would look bad if the child suddenly starts running while the parent walks normally). Therefore, the parent would trigger walking to the next Waypoint upon arriving at the current. The child would then abort the current path and would start to walk to its corresponding points for the next Waypoint.
InLine
This formation is handled in a very simple way so far. The only additional points that are calculated for the child are around the first Waypoint (green spheres in the picture). The movement speed will be adjusted, so that all children arrive at their starting point at the same time the parent arrives at the first Waypoint. Then every child will traverse the Waypoints in the same way the parent does. Therefore, the formation is only formed once around the first Waypoint. Distances between children and parent will not be maintained strictly.
Future implementations
1. Arbitrary Formations
Expand the Child VH Map to allow 2 float parameters. The offset in x- and y-direction. This way the user can define arbitrary formations. The Group Formation ENUM will then "overwrite" these two values to have pre-defined formations, but will also contain an entry "UserDefined", that just takes the offsets provided by the user.
2. Automatically spawn child VHs
If no VH actor is specified as key in the Child VH Map, automatically spawn one at the specified offset.
An example implementation can be found on the GroupMovementTest Map.
Next steps:
- arbitrary formations
- automatically spawn child VHs
- automatic changes of formations based on environment-awareness
- ...
|
---|