I'm currently working on a game and I'm hung up on this particular issue.

I have a ball that is a RigidBody. The RigidBody is located on a path, and the offset of the path is calculated and stored. Also, another offset that is 10 game units more than the current offset is sampled. From this, I know the position of where the ball should be on the path now, and where it should be in the future.

I want to apply forces to the ball to keep the ball travelling along the path. From my research, something like a PID controller could help achieve this. But PID controllers seem to supply an acceleration value and a steering value. The acceleration value is not relevant, as that is supplied by the AddForces update from an outside power source. The steering is also difficult to apply, as the ball does not "steer", but rather just gets influenced based on forces being applied to the ball.

Every solution I have tried and looked into seem to have the following issues:

  1. The ball oscillates wildly as it attempts to keep the path
  2. I am required to give a "speed" and "turning" value, which don't apply to a RigidBody ball (or at least as far as I can ascertain).
  3. The angular momentum is not updated to "face towards" the future position in a reliable fashion, causing the ball to spin up against the barrier until the angular velocity eventually points in the right direction.

If it makes a difference, I am doing this in Godot C#, however the mathematics that are used would likely work in any game engine.

How can I make my RigidBody ball track along a path, with angular velocity being kept pointed in the right direction, and with no other artefacts like oscillation as the ball tries to keep the path?

  • \$\begingroup\$ Do other objects need to interact with this ball, e.g. pushing it faster along its path or blocking/bouncing it back along the path? And do you have any constraints on the shape of the path? \$\endgroup\$
    – DMGregory
    Commented May 26 at 12:50
  • \$\begingroup\$ The ball is travelling along a path, but there is also some geometry that follows the path. The geometry is a road, that acts as a collider for the rigidbody. So, the ball rolls along the road, and the road gives the ball a surface to roll on. There's no real constraints on the shape of the path. I guess the only constraint is that the path is sane enough for someone to control a ball on (so, not suddenly zigzag or have impossible climbs). \$\endgroup\$ Commented May 26 at 13:08
  • \$\begingroup\$ At the moment, apart from the ball rolling along a road, there are no other things for the ball to interact with. It's possible that in the future, it might hit other rigid bodies or something, but for now I'd be happy to just get it to reasonably track along the path. \$\endgroup\$ Commented May 26 at 13:08

1 Answer 1


Given your constraints you might be better off jettisoning the physics system entirely and rolling your own system for placing the ball on the path (it sounds like you've already done a lot of the work for that system anyway, by calculating the ball's offset along the path).

The specifics of how you do that are dependent on your particular situation. For example how are you defining the path? Is it a list of splines? A list of line segments? Etc. But basically you treat the the whole thing as a function where given the inputs (e.g. speed, time elapsed, etc.) you calculate what percentage of the path has been traversed and place the ball at that point in the path.


Sorry, I misunderstood your requirements. Maybe I'm still misunderstanding but it sounds like you need the ball to behave like a RigidBody but ignore forces that are not aligned with the direction of the path. I don't know the Godot physics system so there's probably a better way to do it but maybe try to enforce the constraint yourself at each update? Something like this: before each physics update:

  • Determine the direction of the path at the ball's current location
  • Take the current forces being applied to the ball and "align" them to the path by projecting them onto the direction.
  • Do the same with the velocity of the ball

This is likely to have some issues and require refinement, but the idea should work - filter out any forces that not along the path.

  • \$\begingroup\$ I still want the RigidBody bits, as in, the ball to bounce along the path, hit into other objects and slow down, etc. The ball should also have angular velocity (roll along the path). So, just placing the ball on the path at a given offset would mean I'd have to make my own physics system for the ball rolling along, which is beyond my ability. \$\endgroup\$ Commented May 26 at 23:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .