I want to create a script that can simulate a jump-type movement on a part by adding to the assemblylinearvelocity. Whenever I do change the velocity, it resets within the same frame unless I move the part within studio first.
Im relatively new to scripting so sorry if there’s something blatantly obvious that im missing
I’ve tried changing the anchor from false to true and back again and I’ve tried editing the physical properties of the part which doesn’t fix anything. I’ve also tried adding a bodyvelocity, which didn’t work for me either so I’m fresh out of ideas.
The script:
-- variables and services
local input = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local wfc = game.WaitForChild
local nonh = wfc(workspace,"nonhumanoid")
-- function that sets the assemblylinearvelocity based on workspace.gravity to get the same height(this isn't the issue)
function nonhumjump(height)
nonh.AssemblyLinearVelocity = nonh.AssemblyLinearVelocity + Vector3.new(0,(2*workspace.Gravity*height)^0.5,0)
end
--check for keypress to run the function
input.InputBegan:connect(function(keycode)
local key=keycode.KeyCode
if key==Enum.KeyCode.P then
nonhumjump(4)
end
end)
--prints out the velocity if the velocity is different from its previously measured velocity
local prevvelo = Vector3.new(0,0,0)
RunService.Stepped:Connect(function()
if(nonh.AssemblyLinearVelocity ~= prevvelo) then
print(nonh.AssemblyLinearVelocity)
prevvelo = nonh.AssemblyLinearVelocity
end
end)
Baseplate.rbxl (111.7 KB)