Best way to move a truck without physics?

The issue
So I got this truck that I want to move around ingame by script, not player controlled.
Right now I do RenderStepped:connect and lerp the trucks engines CFrame around.
The other parts are attached by Motor6D instead of welds to make sure they move along.
Some parts I even custom set the velocity to inorder to make sure you can stand on the truck roof for example.

I feel like this puts alot of effort on renderstepped, especially when I do similar treatment for alot of moving parts.

Is there a better way to do this?

  • I can’t have laggy visuals
  • Some parts, atleast, must have realistic velocity
  • It can’t be run by BodyGyro and BodyPosition/Velocity - That stuff always glitches no matter how much you configure it.

So any suggestions on how to do this?

3 Likes

You can probably start by binding that to Heartbeat instead of RenderStepped. See this thread: RunService.Heartbeat switching to variable frequency

1 Like

Ye but that’ll give laggy visuals which isnt acceptable.

Is the vehicle locked to the camera?

Not sure what you mean but the truck moves on its own, in no way related to any camera movement.

Huh. I can’t imagine it appearing laggy to the player. Sorry if it’s too much, but can you provide a video of it with Heartbeat?

Ill switch it and see what happens but Im pretty sure it was laggy when I tried it before.

You need to lerp the movement for it to look smooth.

Hmm it seems like I’ve been using Stepped instead of RenderStepped for a while now…
Heartbeat seems to be sorta same thing.

Had no lag, I guess this is the way to do it then?

1 Like

Yep. A rule of thumb is that, unless you want something to be in lockstep with the Camera, use Heartbeat. Game logic goes in Heartbeat, too.

2 Likes

RenderStepped blocks the pipeline until it is complete, while Heartbeat/Stepped run in parallel with rendering so it is more efficient to do your logic there. These methods all have the same frequency. (once per frame) If you’re syncing something up to the player’s camera, use RenderStepped, otherwise Stepped/Heartbeat is usually best practice.

The difference between Heartbeat/Stepped is that Stepped runs right after animations are updated and right before physics, while Heartbeat runs right after physics updates.

4 Likes

If I were going to do this, I’d use TweenService, updating maybe 15x per second.

The movement won’t look laggy, although it wouldn’t go perfectly along whatever line you have. I doubt it’s very noticeable, and this would move a lot of the lerping work onto the C side which I’d image is more efficient.
I haven’t tested this, so I could be completely wrong

4 Likes

I have never heard of this service before, do they just add cool stuff without announcing it nowadays?! XD

EDIT: Doesn’t make connected parts inherit velocity so it doesn’t help me in this case. However cool stuff, def. going to use for other stuff!

You could try to update velocity on heartbeat like you were doing, and position it with TweenService?
That might take some stress off the lua end, while still allowing you to stand on the truck.