I need to have a little man run around the room. I wrote that if it approaches the border, then it should change the direction to the opposite. But sooner or later it leaves the room anyway. What am I doing wrong? How can a deliberate movement be realized?
Yes, you can rely on navigation. Documentation and PG here : Crowd agents - Babylon.js Documentation
You can also keep the physics running if you set the linear velocity as a vector (crowd agent position - impostor position) multiplied by a max speed.
But be careful if the physics is stuck at some point and the crowd agent keeps going. If that happens, when the distance between the crowd agent and the impostor is to big, then teleport the impostor at the agent position.
In this PG, the purple box is the crowd agent (a box attached to the crowd agent actually) and the grey box is a physics impostor that follows the agent.
You can achieve that with just a call to setLinearVelocity. See lines 91-100