Hi guys,
I just want to say that to begin with I am using a system that disables the standard humanoidStateType
, as it is always set to PlatformStanding
.
In order to still have access to humanoid states
a new StateTracker
system was included.
This system basically works just as good as the standard State Tracking system included in all Roblox games; it has all of the same states, updates automatically, etc.
The only problem with this StateTracker
is that it does not update as fast as the standard system does, which causing errors in scripts that rely on State Change
such as a Double Jump script for example.
Basically the point behind this post is to figure out if I am able to make the system update faster than it currently does. I am thinking about using RunService
but I am unsure if that will help.
Here is StateTracker
system that is being used (a module script):
Summary
local EPSILON = 0.1
local SPEED = {
["onRunning"] = true,
["onClimbing"] = true
}
local INAIR = {
["onFreeFall"] = true,
["onJumping"] = true,
}
local STATEMAP = {
["onRunning"] = Enum.HumanoidStateType.Running,
["onJumping"] = Enum.HumanoidStateType.Jumping,
["onFreeFall"] = Enum.HumanoidStateType.Freefall
}
local StateTracker = {}
StateTracker.__index = StateTracker
function StateTracker.new(humanoid, soundState)
local self = setmetatable({}, StateTracker)
self.Humanoid = humanoid
self.HRP = humanoid.RootPart
self.Speed = 0
self.State = "onRunning"
self.Jumped = false
self.JumpTick = tick()
self.SoundState = soundState
self._ChangedEvent = Instance.new("BindableEvent")
self.Changed = self._ChangedEvent.Event
return self
end
function StateTracker:Destroy()
self._ChangedEvent:Destroy()
end
function StateTracker:RequestedJump()
self.Jumped = true
self.JumpTick = tick()
end
function StateTracker:OnStep(gravityUp, grounded, isMoving)
local cVelocity = self.HRP.Velocity
local gVelocity = cVelocity:Dot(gravityUp)
local oldState, oldSpeed = self.State, self.Speed
local newState
local newSpeed = cVelocity.Magnitude
if (not grounded) then
if (gVelocity > 0) then
if (self.Jumped) then
newState = "onJumping"
else
newState = "onFreeFall"
end
else
if (self.Jumped) then
self.Jumped = false
end
newState = "onFreeFall"
end
else
if (self.Jumped and tick() - self.JumpTick > 0.1) then
self.Jumped = false
end
newSpeed = (cVelocity - gVelocity*gravityUp).Magnitude
newState = "onRunning"
end
newSpeed = isMoving and newSpeed or 0
if (oldState ~= newState or (SPEED[newState] and math.abs(oldSpeed - newSpeed) > EPSILON)) then
self.State = newState
self.Speed = newSpeed
self.SoundState:Fire(STATEMAP[newState])
self._ChangedEvent:Fire(self.State, self.Speed)
end
end
return StateTracker
Would I be able to use RunService.RenderStepped
to increase the rate at which it updates?