I have this disk system in my game where you throw and catch a disk. It works fine (don’t mind the placeholder animations), but when I throw the disk it stops for a second before throwing.
Here’s the throw function:
function diskModule:Throw(disk, direction, power)
local diskModel = disk:FindFirstAncestorOfClass("Model")
disk.WeldConstraint.Enabled = false
disk.AlignOrientation.Enabled = true
disk.VectorForce.Enabled = true
disk.Throw:Play()
local impulse = direction.Unit * power * 2.5 * disk.Mass
disk:ApplyImpulse(impulse)
end
Here are a few potential reasons for the delay and some suggestions to address them:
Tween Delay: The disk.Throw:Play() line initiates a tween animation. Depending on the complexity of the animation or the properties being tweened, there might be a delay before the animation actually starts.
Property Changes: Enabling properties like AlignOrientation and VectorForce might introduce delays depending on their setup and how they interact with other components in your game.
Physics Simulation: If the object being thrown interacts with physics, applying impulses and enabling physics-related components like VectorForce can introduce delays due to physics simulation.
To mitigate the delay, you can try the following:
Reordering Operations: Try rearranging the operations to ensure that critical actions (like applying impulse) are performed before initiating the tween or enabling other components.
Preloading: Preload or set up necessary components before the Throw function is called, so there’s less delay when enabling them or playing tweens.
Optimizing Tweens: Simplify or optimize the tween animation to reduce its delay or improve performance.
Profiling: Use debugging tools or profilers to identify where the delay is occurring and optimize accordingly.
The delay doesn’t come from something other than the :ApplyImpulse() itself; I tested with prints and it was 0.016 seconds between right before the remote event fired and right after ApplyImpulse was called. (by that, also, ApplyImpulse is Async as far as I can tell)
So the delay is definitely in the ApplyImpulse function itself. I just don’t know if that lag is a problem with my game or if it’s just a part of the function.
Hi, if anyone’s wondering, the delay comes from network ownership being set on the server. This delays the physics calculation for the client by that half a second you see in the video.
Now I have to figure out how to make this all work on the client