vicisdev Posted December 19, 2019 Share Posted December 19, 2019 Is there a way to prevent this from happening? I'm making a movement script with cubic-bezier support, but when I render the movement onClientPreRender the server kinda limit the executions. DEMONSTRATION Link to comment
MIKI785 Posted December 19, 2019 Share Posted December 19, 2019 Can you post the code? onClientPreRender is a client event, it has nothing to do with the server. Link to comment
vicisdev Posted December 19, 2019 Author Share Posted December 19, 2019 53 minutes ago, MIKI785 said: Can you post the code? I don't know if it's enough, but basically this is what's called every frame -- self.behavior is a table that describes the animation properties local elapsedTime = os.time() * 1000 - initialTime local time = elapsedTime / self.behavior.duration local progress = bezierInterpolation(time, self.behavior["cubic-bezier"]).x local element = self.element local x, y, z = unpack(initialPosition) local toX, toY, toZ = unpack(self.behavior.to) local newX, newY, newZ = x + ((toX - x) * progress), y + ((toY - y) * progress), z + ((toZ - z) * progress) setElementPosition(element, newX, newY, newZ) if time == 1 then removeEventHandler("onClientPreRender", root, renderHandler) end This function is called every frame, but because the values is too close from each other the API tries to save processing and updates only per second, I guess. 24 FPS 100 FPS Link to comment
Scripting Moderators ds1-e Posted December 19, 2019 Scripting Moderators Share Posted December 19, 2019 1 hour ago, vicisdev said: I don't know if it's enough, but basically this is what's called every frame -- self.behavior is a table that describes the animation properties local elapsedTime = os.time() * 1000 - initialTime local time = elapsedTime / self.behavior.duration local progress = bezierInterpolation(time, self.behavior["cubic-bezier"]).x local element = self.element local x, y, z = unpack(initialPosition) local toX, toY, toZ = unpack(self.behavior.to) local newX, newY, newZ = x + ((toX - x) * progress), y + ((toY - y) * progress), z + ((toZ - z) * progress) setElementPosition(element, newX, newY, newZ) if time == 1 then removeEventHandler("onClientPreRender", root, renderHandler) end This function is called every frame, but because the values is too close from each other the API tries to save processing and updates only per second, I guess. 24 FPS 100 FPS I know that has nothing to do with that, but calling unpack every frame, it is heavy function. You might simply replace it with [], since you know how much data will be returned. 1 Link to comment
MIKI785 Posted December 19, 2019 Share Posted December 19, 2019 Are you just trying to move an object? Wouldn't using moveObject be sufficient? Link to comment
vicisdev Posted December 19, 2019 Author Share Posted December 19, 2019 18 minutes ago, majqq said: I know that has nothing to do with that, but calling unpack every frame, it is heavy function Oh, thanks! I really appreciate this kind of help. 17 minutes ago, MIKI785 said: Are you just trying to move an object? Wouldn't using moveObject be sufficient? No, because I'm trying to make something more robust, versatile. Link to comment
vicisdev Posted December 20, 2019 Author Share Posted December 20, 2019 (edited) 17 hours ago, vicisdev said: Is there a way to prevent this from happening? I'm making a movement script with cubic-bezier support, but when I render the movement onClientPreRender the server kinda limit the executions. DEMONSTRATION Solved! The point is that os.time() returns an integer in seconds, so even if I multiply it by a thousand we miss a lot of information on cents, decimals, units in a range from 0 to 999. Just replace os.time() by getTickCount() and you're good to go, since this returns an integer in milliseconds. Edited December 20, 2019 by vicisdev Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now