i am simply trying to push the player forwards to where they are facing
however the BodyVelocity is not moving the HumanoidRootPart, except for when i put in a new Vector3
i’m 100% certain the code is correct
but i really think it could be that i’m using a StarterCharacter but i dont know whats in the character that could be interfering with it
--this one works with a hard coded vector (not in my real code)
--but if i use this, the velocity will not push me where i'm facing
local bv = Instance.new("BodyVelocity")
bv.Parent = hrp
bv.MaxForce = Vector3.new(10000,0,10000)
bv.Velocity = Vector3.new(20, 0, 20)
--this one for no apparent reason does not work
local bv = Instance.new("BodyVelocity")
bv.Parent = hrp
bv.MaxForce = Vector3.new(10000,0,10000)
bv.Velocity = hrp.CFrame.lookVector * 20
For what it’s worth, this has a magnitude of 20 * 1.414 which is 28.28 instead of 20. For a fair comparison, you would need to multiply lookVector by about 30.
The only difference between the two scripts is the Velocity property, right?
What I meant in my last post is that hrp.CFrame.lookVector * 20 has a magnitude of 20, but Vector3.new(20, 0, 20) has a magnitude of almost 30. Does anything change if you multiply lookVector by 30 instead of 20?
i see what you mean now, but it still doesnt do anything
i should probably note that i tried using higher values before this post, still didnt do anything
Tested out some forces and found BodyForce to be particularly useful in this scenario. So if BodyVelocity isn’t necessary for you try this:
The following code is an example and worked on a baseplate. The primary caveat is that I didn’t include friction defiance, the formulas and API for disregarding friction can be found here.
A simple workaround to this would be to just detect when Humanoid.FloorMaterial ~= nil and just increase the multiplier until it overcomes friction.
--// This was tested in a local script, consider reformatting this for server-sided physics
local RS = game:GetService("RunService")
local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local hrp = char:WaitForChild("HumanoidRootPart")
--// BodyForce: Applies a basic force using the .Force [vector] to the .Parent
local bodyForce = Instance.new("BodyForce")
bodyForce.Parent = hrp
--// We could use v.AssemblyMass, however, that method resulted in disproportionate weight
local function GetMass(model)
local m = 0
for _,v in ipairs(model:GetDescendants()) do
if(v:IsA("BasePart")) then
m += v:GetMass()
end
end
return m
end
--// W = F = m * g: formula used
--// We could declare these inside Heartbeat to have it update on the fly, but that would take up more resources
local mass = GetMass(char)
local weight = workspace.Gravity * mass
--// Update the Force to match the HRP LookVector
RS.Heartbeat:Connect(function()
bodyForce.Force = hrp.CFrame.LookVector * 1 * weight --// 1 is your changeable multiplier
end)