2D RVO more questions

Hi Aron, thank you for the support thus far. I own the latest pro version ( old version + upgrade ).
I’ve built a 2d game with your wonderful library in the past, when 2d RVO wasn’t available, and rewrote the movement classes in such a manner that they used rigid bodies. In that game I didn’t use RVO, instead I would have one of the units be disabled for 1-2 seconds when touching another, so that the other one could push it away using physics. Silly method, however it worked fantastically.

At the present time I’m working on a project where the quality of movement is highly relevant to the project, so I need to use the RVO, specifically since I have about 50-100 units running at a time. In my game, I’d have :

  1. Different teams, two or more having RVO that move independently of one another.
    So I’d like to ask : should I create two an RVO simulator for each one ?

  2. If possible, the movement should be controlled by adding velocity to RigidBody2d’s ( with box colliders and circle colliders ).
    Would you have any suggestions, perhaps guidelines or scripts already made for this ? and would this method be a lot more memory consuming than just using your RVO ?
    The reason is : I need other objects to collide with these.

  3. Some of my units will start moving only when they’re looking in the respective direction ( tanks for example ) , however they still work with the RVO.
    Does the RVO provide this or does this need to be implemented ? My guess would be that I’d just lock them and rotate them until the rotation is similar to the direction.

  4. I’m planning to use a navmesh, not a grid, however. there is no navmesh scene example for 2d.
    Would it be possible to create one ?

Huh, very interesting solution :slight_smile:

  1. No, instead you can set the ‘layer’ field on each RVOController and then also set which other rvo layers that the agent should avoid. With this you can make the two teams independent.

  2. If you are using the included movement scripts (e.g AIPath) this should move out of the box. However since you have 50-100 units you may want a custom movement script more optimized for your particular game.
    There is no tutorial specifically for rigidbodies, however if you look at the RVOController documentation there is a code snippet for how to move a Transform component using RVO. That code could easily be changed to use a rigidbody by using rigidbody.MovePosition and change the method to FixedUpdate instead of Update.

  3. That is tricky. The RVO algorithm really wants to be able to move agents in any direction at any time for good local avoidance. You can of course constrain the movement so that it doesn’t do this, but local avoidance quality may suffer.

  4. You should know that currently the recast graph does not support 2D colliders. It does support being rotated to the 2D plane though. With a rotated recast graph it should work exactly the same as a recast graph in the XZ-plane though. Why specifically do you want to use a navmesh here?

Thanks for the replies !

  1. Just for clarification : I can have units on the same layer receive different orders ? for example units in Area A move to Area B, while units from Area B move to Area A ?

  2. rigidBody2D.MovePosition sounds interesting, I’ll look into that a bit more later today, however, is there any way to calculate the speed depending on rigidBody2D.velocity ? I’d like to use velocity for movement, as I used in the previous project and it worked great.

  3. Regarding rotation : wouldn’t it be a possible solution to just set the velocity to 0.001 while I still rotate the object on the respective direction, then after the rotation took place, have it start moving at it’s normal velocity ?

  4. Most importantly : I believe I need a navmesh because many of my units are vehicles ( cars, tanks ).
    On a grid, they would go on the nodes, around 45 degrees, for example : if my unit would go on a distance of 20 on X, and 10 on Y, it would move in a zig-zag, so that would mean : rotate on the spot, then move, repeat - which looks highly unrealistic in the case of a car, even if I’d start the movement when the distance between unit direction and angle is 22 degrees or less - there would be a pause in the movement. If I use smoothing (which I’m uncertain how would work together with the RVO) , they might hit the corners of buildings ( specifically since the tanks/cars are box colliders ).
    In the case of a navmesh, they’d move constantly, with small variations in angle.

  1. Yes. All agents are independent.

  2. How you do the movement is entirely up to you (if you use a custom movement script, not AIPath).
    Check out the example code I linked in the previous post. You just need to tell the RVOController in which direction you want it to move and it will tell you how it should move to avoid collisions.

  3. You can prevent the agent from moving, that’s not the hard part. The hard part is that other agents nearby it will expect it to cooperate and possibly move out of the way. If it does not do this then the local avoidance quality may suffer a bit.

  4. You can use the Funnel Modifier or the Raycast Modifier which will simplify the path so that it looks similar to a path on a navmesh.
    You can also smooth the path using the Simple Smooth Modifier, just make sure it doesn’t smooth it too much. Take a look at this image: