Jump to content

Recommended Posts

I've this code but it sometime work sometime not. Please help me.
 

AddComponentPostInit("locomotor", function (self)
	self.timemoving = 0
	local oldOnUpdate = self.OnUpdate
	self.OnUpdate = function(self, dt)
		oldOnUpdate(self, dt)
		local is_moving = self.inst.sg ~= nil and self.inst.sg:HasStateTag("moving")
		local is_running = self.inst.sg ~= nil and self.inst.sg:HasStateTag("running")
		if is_moving or is_running then			
			self.timemoving = self.timemoving + dt
		else		
			self.timemoving = 0 -- sometimes this code is not executed.
		end
	end
end)

Thanks you.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...