Hey,
I’ve been making a trainkit using physics, and I’ve stumbled on a problem. The problem is that whenever I hold down the “R” key and let go, the throttle sits at that which is what I want to change.
What I want to achieve is that when a user hits R the train should start to roll on the tracks and going up makes it faster.
ThrottleValue = math.clamp((1-Deltatime) * Current + (Deltatime * Goal), 0, MaxThrottle)
The line above is making it so that when you hit the key it goes up and when you release it stays on that number.
What can I change to make it so it continues so speed up when only pressed once?
here is the relevant code for this:
local ThrottleDirection = train.Important.Throttle.Value or 0
local ThrottleValue = train.Important.Current.Value or 0
local MaxThrottle = 100
local ThrottleIncPerSecond = 20 -- 4 seconds to get to 100.
-- inside the update function
ThrottleDirection = (KeysDown.LShift and 1 or 0) + (KeysDown.LCtrl and -1 or 0)
local Current = ThrottleValue; -- hold our current state
local Goal = Current + (ThrottleIncPerSecond * ThrottleDirection)
ThrottleValue = math.clamp((1-Deltatime) * Current + (Deltatime * Goal), 0, MaxThrottle)
thanks.