hello. I have a localscript that applies an impulse on the cube when the player clicks, so that the cube moves towards the mouse. but for some reason, the cube gets stuck midair sometimes, and I don’t know why.
It looks as though this may be the sleep system: Sleep system | Documentation - Roblox Creator Hub. I don’t remember how to try and mitigate this bug, but the problem is roblox tries to save simulation costs by not simulating inactive parts. Try looking up some info, hope it helps!
It’d help us if you provided the script so we could take a look.
Copy/Paste it here and put 3 backticks (```) before and after the entire code so it formats properly.
local IMPULSE_FORCE = 30
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local mouse = player:GetMouse()
local cube = workspace:WaitForChild("Cube")
mouse.Button1Down:Connect(function()
print("click")
local mousePos = mouse.Hit.Position
if mouse.Target then
print("hit")
cube:ApplyImpulse(cube.Position:Lerp(mousePos,IMPULSE_FORCE))
else
print("miss")
end
end)
everything in my game is on the Z axis (the Z position is 0). I use an invisible wall to make sure I’m getting the mouse position on the Z axis.
also, it doesn’t break randomly. there seems to be a “zone” on the left side where it always breaks.
yeah, I just tested it and I think this is the issue!
but why doesn’t my part stay awake? documentation says that an impulse should keep the part awake.
Your part is sleeping, try doing this on a normal and not local script and setting network ownership to nil, it worked for me when done on the server.
you can detect the click on the client and fire a event for the server to apply the impulse
I’m not entirely sure why it won’t stay awake, or what is the best way to stop this from happening. The best i can find is this from boatbomber: AlarmClock - Wake up sleeping BaseParts and prevent Sleep - Resources / Community Resources - Developer Forum | Roblox. Here’s a short description of the solution by boatbomber:
To keep parts awake at minimal performance cost, I determined that the best way is to softly push the object towards the ground. We only push it when the Velocity is 0,0,0 as any other velocity means it must already be awake. We push it gently down, because if it’s asleep then it must be resting on something so a downward velocity has almost no risk of actually causing the part to move- just wakes it up.
Though as I typed this Asta gave an answer that I think may also work, possibly better, so I think you should try that one first.
I tried this, but it’s really laggy. is there any way to do it on the client?
this doesn’t work
also, how is possible for a part to be sleeping if it’s midair?
Sorry ): I don’t know how to solve this. I believe this is a bug that Roblox is trying to fix.
I wish you luck in finding a solution!
After checking, there is a pending update in the latest changelogs that will hopefully help.
Release notes for 665 | Documentation - Roblox Creator Hub