While working on a game, I encountered inconsistent behavior when applying AssemblyLinearVelocity to a character. To isolate the issue, I created a separate place file containing only a part that the player can step on. The code is as follows:
local LaunchMine = script.Parent
local canHit = true
local function onTouched(hit: BasePart)
if hit.Parent:FindFirstChild("Humanoid") and canHit == true then
local rootPart = hit.Parent:FindFirstChild("HumanoidRootPart")
canHit = false
if rootPart then
rootPart.AssemblyLinearVelocity = Vector3.new(0, 500, 0)
print("Done!")
end
script.Parent.boing:Play()
task.wait(2)
canHit = true
end
end
LaunchMine.Touched:Connect(onTouched)
Issue
Despite using the same code in both cases, the velocity physics behaves inconsistently:
Inconsistent Behavior:
No Behavior at all:
System Information: 11th Gen Intel(R) Core™ i7-11800H @ 2.30GHz 16.0 GB GPU 0 NVIDIA GeForce RTX 3050 Ti Laptop GPU
From experience, I’ve used ALV for tracking current velocity rather than applying it, because of this very reason. You can use a temporary BV (BodyVelocity) instead, because it will always be applied.
local Debris = game:GetService("Debris")
local LaunchMine = script.Parent
local canHit = true
local function ApplyBV(Parent)
local BV = Instance.new("BodyVelocity", Parent)
BV.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
BV.Velocity = Vector3.new(0, 500, 0)
Debris:AddItem(BV, 0.25)
end
LaunchMine.Touched:Connect(function(hit:BasePart)
if canHit == false then return end
canHit = false
if hit.Parent:FindFirstChild("Humanoid") then
local rootPart = hit.Parent:FindFirstChild("HumanoidRootPart")
if rootPart and rootPart:IsA("BasePart") then
ApplyBV(rootPart)
print("Done!")
end
script.Parent.boing:Play()
end
task.wait(2)
canHit = true
end)
Thank you for your reply! While BodyVelocity is an option, Roblox has marked it as deprecated. What’s the most frustrating is that I’ve built a custom physics system for my game, along with other mechanics that rely on .Velocity and .AssemblyLinearVelocity and they suddenly stopped working a few days ago.
I’d prefer to avoid rewriting large portions of code if Roblox ends up fixing the issue. However, if it isn’t resolved soon, I’ll likely switch over to your BodyVelocity idea as a workaround.
I see, that’s completely understandable. After looking around the forum a bit more, I actually found a solution. Simply put, you just have to add a few steps with a for loop to ensure that LAV actually gets applied. It’s pretty neat, and I might use this method as well.
To apply this, just replace the ApplyBV function with this one, and then call it from the same place.
local function ApplyLaunch(Parent)
for i = 1, 3 do
Parent.AssemblyLinearVelocity = Vector3.new(0, 500, 0)
task.wait(0.05)
end
end
Any idea why it got inconsistent suddenly? A lot of the mechanics I’ve coded over two years ago that used .Velocity, and another coded about 8 months ago which used AssemblyLinearVelocity, stopped working this week!