I’m trying to learn how to rig a car following Sleitnick’s tutorial
How to rig a car . I have one question that i want to ask? How can the steering speed be calculated in this way:
> local steergoal = -seat.SteerFloat * 30
> local steer = steer + (steergoal-steer) * math.min(deltatime*seat.TurnSpeed,1)
i have little experience in runservice and anything related to this service so please go easy on me.
What is the
deltatime variable defined as?
the delta time is a parameter that is passed through the function of heartbeat
really sorry for the late reply
No problem. I believe what the delta time is doing here is that it’s running every frame, so as to provide a smooth turn/steer effect.
could you explain it a little bit clearer cause i don’t have much experience on runservice. I only know barely what the devhub provide
So, you know how
Heartbeat runs every frame?
deltaTime parameter basically provides a parameter between each event (take this with a grain of salt, not an expert on this).
Try running this code in the command bar:
local e = game["Run Service"].Heartbeat:Connect(function(deltaTime) print(deltaTime) end) wait(5) e:Disconnect()
This basically prints the deltaTime to help you visualize it.
Here’s a random tutorial I found, hope it helps.
I haven’t seen anything about this, so I will make this my first tutorial.
What is DeltaTime?
DeltaTime is the time between events. This is extremely useful, often used to make sure frame rate makes no difference on what happens. The focus of this thread will be on DeltaTime with RunService events, wait, spawn, and delay.
Why use DeltaTime?
Since DeltaTime is the time in between events, this can be used with RunService events/wait when timing is important.
RunService events are tied directly …
so from what i understand is what Sleitnick do is to calculate how many degree to spin during each frame right? It is kind of too confused right now
Nope no calculations involved really, what it does is lerp the current steer towards the goal steel.
local function lerp(start, goal, alpha)
return start + (goal - start) * alpha
--Notice the similarities with the below steer equation?
--local steer = steer + (steergoal-steer) * math.min(deltatime*seat.TurnSpeed,1)
--alpha is equal to
@ThanksRoBama explains the equations behavior and hence it’s purpose in another similar post:
It changes by a small fraction every update. This fraction is determined by the frame-frate and the
moveAcceleration , which represents the acceleration from a complete stand-still. All of this causes it to
asymptotically go towards the target velocity, which means as it gets closer to the target speed, it accelerates slower and slower, so we get a very smoothed-out speed change as it gets up to speed or slows down, but it still accelerates pretty fast and feels pretty responsive when the player suddenly changes direction
Provide responsive fast controls but doesn’t directly go towards the goal so you can do stuff like tapping input in order to control the car better at small turn speeds.
that is strange, i check again the equation of sleitnick and it doesn’t work anymore! it spins quite litte compare to yesterday when i did it
and the part you say about it gets closer to the target speed, it accelerates slower and slower. What do you mean by that? it starts to get really confused now.
and one more thing that i want to ask, why should we use the localscript to drive the car instead of the serverscript