I’m trying to create an addon to my weapon script which allows the character to strafe left or right by pressing “q” or “e” but cannot figure out how to do body forces to make this.
Mouse.KeyDown:connect(function(Key)
if Equipped == true and Down == false then
if string.lower(Key) == "q" then
local bodyForce = Instance.new("BodyForce")
local Left = Vector3.new(-100, 0, 0)
bodyForce.Parent = Character.HumanoidRootPart
bodyForce.Force = bodyForce.Parent.CFrame:vectorToWorldSpace(Left)
end
end
end)
Could anyone could suggest or give any help on how to successfully create this, It would be much appreciated.
If using BV doesn’t work, you could try doing something like this
Mouse.KeyDown:connect(function(Key)
if Equipped == true and Down == false then
if string.lower(Key) == "q" then
local left = Vector3.new(-20,0,0)
for i = 0, 1, .05 do
local CharPos = character:GetPrimaryPartCFrame()
character:SetPrimaryPartCFrame(CFrame.new(CharPos):vectorToWorldSpace(Left.X * i, Left.Y, Left.Z))
end
end
end
end)
Your best option is to set the velocity of the HumanoidRootPart directly. This will also allow you to include velocity from gravity as part of the strafe.
Don’t set the CFrame of the HumanoidRootPart, because that won’t be physically simulated and the character will be able to move through obstacles.
It’s not BodyForces, what @Shardwielder is trying to say is, under every basepart there’s a velocity property which you can change. It works like bodyVelocity except the bodyVelocity kind of lerps the movement. Just do
local left = Vector3.new(-100,0,0)
HumanoidRootPart.Velocity = left