How could we clamp physics vehicle in horizontal direction?

I have used the same vehicle as this tutorial.

https://developer.playcanvas.com/en/tutorials/vehicle-physics/

Vehicle has a continuous jerk movement following this code.

    var position = new pc.Vec3().copy(this.entity.getLocalPosition());
    position.x = pc.math.clamp(position.x, min, max);
    this.entity.rigidbody.teleport(position);

Please help me out with this.

Hi @yash_mehrotra! I’m not realy familiar with this, but where do you define min and max?

These variables are just for example. I have already tested and verified the values that I have used in the code. You could define your values if you want.

It’s better to share the actual code you use. I will check your project later today.

@Albertos Here is the link of the editor. Refer to the vehicleController script.
https://playcanvas.com/editor/scene/1635327

Your project is so complex that I can’t find where you are moving the vehicle forward. I suspect the above code is conflicting with the force you are applying to the vehicle. I think if you teleport a rigidbody while a force is applied, the force is disrupted and that is probably the jerking you see.