Direct movement?

Hi guys I am maybe missing something trivial here but I can’t just get my agent to move directly from gamepad input. He either moves with significant unpredictable lag aiPath.Move or doesn’t move at all tried with Move + FinalizeMovement or using RVOController. Is there an example moving agents with Gamepad? This seems like something that should be easy, I mean I am switching from Navmesh where simple NavmeshAgent.Move does the trick without any other stuff to implement to make it work.

Thank you.

Hi

Are you saying there is a large delay when using AIPath.Move? It should at most have a one frame delay I think.

[EDITED] Sorry for wrong answer.

What kind of lag?
Does the game reduce in FPS? Is the agent’s movement not smooth? Is there a delay between your gamepad input and the agent’s movement?

Kind of hard to describe, it is not gamepad delay, for example if I keep changing the delta value in Move each frame it will not move at all, it just starts moving if the delta is the same for atleast 2 frames.

Anyway will play with it a bit longer if I can find a better description of the behaviour.

Here is an example I just recorded, as you can see it should move all the time but only keeps moving when I don’t change the direction for few frames.

[EDITED] Video removed

That does indeed look strange.
Do you think you could post the exact code that you are using?

For the movement there is nothing special just a Grid graph and AIPath on the agent. With Move call in the Update method when joystick magnitude is bigger than 0. Nothing really to post.

_aiPath.Move(p_delta); // Where p_delta is normalized joystick input vector*constantAgentSpeed.

Nevertheless. It does help for context :slight_smile:

Keep in mind that AIPath.Move takes an absolute movement delta, not a velocity. So it should be multiplied by Time.deltaTime somewhere.

Yep it is actually. in the speed. But even if it wasn’t it should either not move at all or move at all times so didn’t really found that significant as that would just affect the amount of movement.

Hi

Could you debug the vector that you are giving to the Move function?
E.g. use

Debug.DrawRay(ai.position, delta / Time.deltaTime, Color.red);

Sure, but the vector is fine atleast when I switch to NavMesh.Move it works right away.

[EDITED] Video removed

Ok got it, it is kind of a quirky problem so if anyone has the same one here is the explanation.

Firstly what I forgot to mention is that I use RigidBody on the agent, I didn’t think this was relevant but it sure is as I delved to the A* code and if you use Rigid on the object it is using rigid.position instead of transform.position. Nothing wrong with that, however internally Unity applies this rigid transformation to the actual gameobject at fixed time steps and after that it uses it to update rendering obviously. For some reason if you change the rigid position in nonlinear way (notusing same direction of change) this never happens, if anyone has an answer to this I would like to know.

Solution however is pretty easy once you know what is happening, you either move the call to FixedUpdate or enable rigidbody interpolation.

Anyway thanks for the help Aron.

1 Like