Hi there,
I’m wondering what the correct way to handle players and RVO is? My AI use the pathfinding, but my players are directly controlled (no pathfinding). Should I just put an RVOObstacle script on them? Or is there a better way of handling this?
Thanks!
Hi
The best way is to attach an RVOController component to the player but make sure it’s velocity is set by the player input.
You can find an example of this in the script ManualRVOAgent.cs. Essentially you just need to set
rvoController.velocity = v;
each frame, where v is the velocity that your player moves with. This will disable RVO calculations for that agent for one simulation step and other agents will be able to know the direction the player moves with.
Hi Aron, thanks for the response! Velocity didn’t have a setter, but I found RVOController.ForceSetVelocity
in ManualRVOAgent.cs. It seems to work relatively well. However if I stand still in the path of an NPC they seem to freak out and rotate side to side (while ultimately still just walking towards me) until eventually they walk into me and stop.
Is this avoidable behaviour? Could it have anything to do with the fact that I only update both NPCs and player characters in FixedUpdate?
So I made sure I was updating with Vector3.zero velocity when not moving (which I wasn’t previously). Which alleviated the extreme behaviour. But on approach to a stationary player they still fake left and right repeatedly until eventually moving to the right. I have tried setting players priority to 1 as well, though I’m not sure this had much of an effect.
Hi
Do you think you could show a video of this? It might be possible to avoid with some parameter tweaking or perhaps smoothing of the player velocity, but I am not sure.
Perhaps. You should call ForceSetVelocity every frame, otherwise it may revert to not being player-controlled.
Right, it does in the beta. However it is equivalent to calling ForceSetVelocity.
Of course! So this is the wobble (the character rotates towards the velocity to highlight it better):
I tried calling ForceSetVelocity in Update instead, however it didn’t fix the wobble.
Should I be using the beta? Is there a lot of code breaking changes to it?
Hm… It is possible that it is just happens due to coincidence. The RVO algorithm does not guarantee that wobbling behavior does not happen.
I did however discover that in some 4.0.x version I have managed to break the ForceSetVelocity call though. Due to some other changes it will assume the manually controlled agent has a velocity of zero at all times.
I don’t think this is the cause of the issue though, but you probably want to fix it.
You can do that by replacing the Pathfinding.RVO.Agent.ForceSetVelocity method (note, this is not the method on the RVOController) with this
/** \copydoc Pathfinding::RVO::IAgent::ForceSetVelocity */
public void ForceSetVelocity (Vector2 velocity) {
// A bit hacky, but it correct to a large precision
// assuming the agent does not move a very large distance in a single frame
nextTargetPoint = CalculatedTargetPoint = position + velocity * 1000;
nextDesiredSpeed = CalculatedSpeed = velocity.magnitude;
manuallyControlled = true;
}
Thanks for this! I have only just gotten back onto my AI, forgive the tardy reply! I assume this is already included in the latest release? As I will update to that very soon.
I’ll keep going and ignore the wobble for now, maybe address it in the future if it’s still an issue.
Thanks!
Hi, yes that fix should be included in 4.1.10.