Moving rigidbody along spline, and being able to use physics

Hi,

So I’ve been trying to make a rigidbody along a spline that I’ve created, but I’m stumped about how I’m supposed to do this while the rigidbody (right now, and for testing a box) should stay on the spline, while also keeping it in the physics-simulation. I’ve seen examples done in iTween, on this examples page, namely the “Path-constrained characters” one, and “Using PutOnPath and PointOnPath”, but it seems like the objects accelerates when points have higher distances between eachother.

What I have done:


  • I can fetch points on the spline (made by a bunch of bezier curves)
  • I can fetch them by time-percentage, but also on distance, because I’ve done an arclength approximization, so I can get a constant speed when moving on the spline.

I think those are the vital parts for getting this to work(?). What I want to do is getting the object to move along the path, even if the speed to move along the path would be high, and I want the object to still reach to obstacles, hills and so on that I would put on the path. Anyone has good idea?

Thanks for reading (and hopefully helping =) )

As taylank said, calculate either the next position the rigidbody should go and move it there with MovePosition, or calculate the velocity towards that point and set its velocity. Either way, do this in FixedUpdate(), that will keep all changes in the physics timestep and it will work physically. Notice that deltaTime IS fixedDeltaTime in the FixedUpdate loop by default, so no need to use fixedDeltaTime there.