March 14, 2017 at 10:19 #19148
I would like to implement a horde (or multiple hordes) of zombies rushing towards the player, and new zombies will be continuously added at the back. The zombies does not need to have a fixed formation, but ideally they should keep some distance between each other while moving as a group, so they look like a real horde. What is the best way that I can go about implementing this?
Currently there are a few issues/questions that I have:
– The premade formations are too rigid, and if I don’t add any formation, they still line up along the vector field which looks terrible.
– Is there a way to make characters not overlap each other without the use of colliders and rigid bodies? Physics processing seems to take a lot of time, up to 50% of total frametime.
– How to make sure that the newly spawned zombies will join the group and move along smoothly?
– If a zombie trip and fall or shot dead, it should block the way, so other zombies must maneuver around it. How can this be achieved?
Thanks in advance for any help.
March 14, 2017 at 10:48 #19151
- This topic was modified 1 year ago by ethan.tqa.
Thanks for your post.
I am assuming that you own Apex Path and Apex Steer, since you mention formations.
I’m not entirely sure what you mean by “line up along the vector field” or why this looks terrible. Could you show a picture of how it looks and what you want instead?
You can achieve characters not overlapping simply by using the “Steer for Separation Component” and setting the unit radius (UnitComponent) large enough to encompass the units’ sizes.
It sounds like you have a single unit group, so if you maintain a reference to this group you can simply add any newly spawned zombie to the group, at which point they will join their vector field movement. You add them by getting the unit facade for the particular zombie and calling Add on the group.
Zombies tripping, falling or dying and providing blocked points could probably be achieved in at least two ways: Using the Unit Avoidance component and increasing the “determinism” for those units that block other units and disabling the ‘swarming’ feature of the Steer for Separation component, or creating an Advanced Dynamic Obstacle in place of the fallen/dead zombie, triggering new vector field generation around the obstacle.
Advanced Dynamic Obstacles is an add-on asset that we provide through the Asset Store.
March 14, 2017 at 11:15 #19153
- This reply was modified 1 year ago by Rami. Reason: Fixed wrong information
Thanks for replying, I do own both Path and Steer.
Regarding the line up problem, you can take a look at these screenshots: http://imgur.com/a/nwfY6. It is much more obvious in motion though. What I want is maybe add some randomness in the way they move, so that they don’t form perfect lines like that.
About grouping, I might have more than 1 group, coming from different directions. If I have already called MoveTo and the group has already reached the destination, then add a new zombie at the back, will calling MoveTo again makes him move with the group?
March 14, 2017 at 11:46 #19158
- This reply was modified 1 year ago by ethan.tqa.
The easiest way to apply some randomness to their movement would probably be to write your own steering component that simply outputs some amount of randomness.
In regards to grouping, you will need to know which group to add the zombie to, however you refer to it is up to you.
After adding the unit to the group I don’t think you actually need to call MoveTo, despite what I wrote previously. I apologize for the confusion. SteerForVectorField should pick up that there is a vector field and start moving by it. Even if the unit starts outside of the vector field, it should issue a “solo path” to the group and then follow the vector field as soon as possible.March 16, 2017 at 10:00 #19196
Thank you. I have a few follow up questions:
– Despite having steer for separation with sufficient distance value, the agents still overlap each other pretty badly, especially agents from 2 different groups. How can I fix this, without the use of colliders?
– What should I do to make sure that when the zombies in the front have reached target, the ones behind won’t push them and instead stay there and wait?
– There are big CPU spikes caused by physics updates, what can be done about this?
– Is it a must to have rigid body in order to use height map sampling?March 16, 2017 at 11:47 #19199
Steer for Separation will only separate units in the same group. So, either your units all have to be in the same group, or you will need to make a custom version of Steer for Separation which separates from any other unit. You could also attempt to tweak Steer for Unit Avoidance so that it helps you separate units, since Unit Avoidance works against any other (Apex) units.
In regards to avoiding zombies from the back pushing zombies in the front, there are multiple approaches, however none of them come without a little bit of effort. You could try to make formations work for you, so that the units form up in a formation at the destination. You will probably need to make a custom formation type and possibly modify the Steer for Formation component. Another option is to use AI in a way so that units simply stop their movement when they detect another unit in front of them that is stationary, for an example. You could also attempt something simpler like polling distances to units in same group, or using collider triggers to signal ‘stop’ to units behind or similar.
The CPU spikes are most likely not related specifically to Apex components, since we don’t add forces or anything of the like. You will most likely need to tweak your setup to be less dependent on physics if you see physics spiking.
There is no requirement to use a rigidbody for Apex components. However, some of Unity’s collision detection logic is based on the assumption that rigidbodies are present.
You must be logged in to reply to this topic.