As most of you know, BodyVelocity is declared deprecated and is not recommended by others in the community. The problem is that my script relies on BodyVelocity, but I don’t want to use it because its apparently unsafe. LinearVelocity, a known replacement for BodyVelocity, does not work for me as well as some other solutions.
I am at the beginning stages of creating a game based on soccer/football. I am trying to start off with the mechanics of the ball making it react to when touched by the right foot of the Player. When touched, I want the ball to bounce up a tiny bit and roll in the direction it was touched at. BodyVelocity does this well, doing what I prompted of it. LinearVelocity however, does not do it correctly just going. BodyForce is deprecated as well, and I would try VectorForce but I don’t think it has a property that can mimic BodyVelocity.Velocity. Are there any solutions I am possibly missing? Or am I missusing LinearVelocity in a way?
Here is the script using BodyVelocity:
local Services = {
Players = game:GetService("Players"),
Debris = game:GetService("Debris"),
ReplicatedStorage = game:GetService("ReplicatedStorage"),
Workspace = game:GetService("Workspace")
}
local ball = script.Parent
local Table = {}
local function onBallDribbled(root)
local Settings = {
Kick_Timer = 0, -- Ignore
Kick_Slowdown = 5, -- Ignore
Kick_Force = 20
}
local Direction = CFrame.lookAt(root.Position, ball.Position).LookVector
if Direction.Magnitude < 0.001 then
return
end
local Velocity = Instance.new("BodyVelocity")
Velocity.Parent = ball
Velocity.MaxForce = Vector3.new(1, 1, 1) * math.huge
Velocity.LineVelocity = (Direction.Unit * Settings.Kick_Force) + Vector3.new(0, Settings.Kick_Force /1.05, 0)
Services.Debris:AddItem(Velocity, 0.2)
end
ball.Touched:Connect(function(Part)
local Character = Part.Parent
if not Character then
return
end
local Player = Services.Players:GetPlayerFromCharacter(Character)
local Humanoid = Character:FindFirstChildOfClass("Humanoid")
local Root = Character:FindFirstChild("HumanoidRootPart")
if not Player or not Humanoid or Humanoid.Health <= 0 or not Root or table.find(Table, Player) then
return
end
if Part.Name == "RightFoot" then -- Just a base for when I get to specific movements.
onBallDribbled(Root)
print("right")
else
print("not right")
end
end)
When using the LinearVelocity, I’d just change the Velocity to LineVelocity. But seeing the name of the property I should’ve probably known it would just go straight. And of course, there is a possibility using BodyVelocity isn’t as big of a deal as I think it is.
Note - As shown above I am planning on making it slow down as it rolls. Its optional but if you can include a tip on doing that with the solution you’ll save me a ton of time.
Thanks in advance.