# Making autonomous car

So I am making a platfromer game, and I will have players jump on top of trucks until they reach the end of the level, but the issue is that I can’t manage a good looking way for the trucks to be moving in a natural car fashion way, best I could come up with was make the truck and attach a `HumanoidRootPart` infront of it and weld them together so the body of the car gets dragged with the `HumanoidRootPart`, while that works for moving it in a somewhat straight line, the moment you do a hard turn or when the car is falling, it looks very cartoony and unrealistic. Is there anyway I can go around this or maybe position the humanoid somewhere that would make the truck move naturally?

1 Like

So you will want to use a BodyAngularVelocity in order to make smooth turns, and a VectorForce to keep the force applied in object space. You can also use BodyVelocity, but remember to convert it over to local space by setting the velocity to truck.CFrame.LookVector * speed

Trucks will probably be hitting eachother, and if I make a script that will give it forces and not account for deviation, that wouldn’t work.

if you use physics, which those use, that actually is the way to do it, as opposed to CFrameing in a loop

Is there some kind of tutorial or any article or wiki I can read to understand what you are talking about please?

Yes, just understand this:

• Use body movers (bodyPosition, bodyVelocity, etc.) when dealing with unanchored items that you want roblox physics to act on

• Use CFrame when you want to make something move smooth using math, most of the time you will need to do this from a local script

And how am I gonna account for deviation? What these movers do is just keep the Truck moving in a predictable direction, or am I missing something?

If you use a VectorForce, this actually will be better than a BodyVelocity because it will apply a force wherever the truck is facing. So yes, it does account for deviation

By deviation I mean, if the truck is going to Point A and it gets hit by something that will substantially move it away from that already set velocity which was meant to bring it to Point A, how am I gonna account for that? Something like pathfinding is what I am trying to achieve.
Say for example the truck is going in a road, it gets moved away from the road, it wouldn’t just keep going to wherever it got moved to, it has to go back to the road.

But I guess I wouldn’t need this yet, I think `VectorForce` would manage the trick. Thanks!

Nope, for that, use a BodyPosition, you set the position and it keeps trying to go towards that:

1 Like