Help with forcing a player to go forward with a BodyVelocity..?

Hi all, so in my game I’m planning to have a hammer that propells you forward, just like the Jade Hammer in Roblox BedWars (yes im a fan of that game).

However, I’m using BodyVelocity and cannot get the Test Zombie to move forward.

What’s happening:

Sorry for the lag btw, I’m using the default Roblox recorder.

Image:
imagethingdevforumpost

ServerCode:

local tool = script.Parent

local remote = tool:WaitForChild("BlastEvent")

remote.OnServerEvent:Connect(function(player, target)
	if target then
		if target.Parent:FindFirstChild("Humanoid") then
			local root = target.Parent.HumanoidRootPart
			local velocity = Instance.new("BodyVelocity")
			velocity.MaxForce = Vector3.new(6000,6000,6000)
			velocity.Velocity = Vector3.new(-100,0,0)
			velocity.Parent = root
			wait(0.5)
			velocity:Destroy()
		end
	end
end)

ClientCode:

local tool = script.Parent

local remote = tool:WaitForChild("BlastEvent")

local plr = game.Players.LocalPlayer

local mouse = plr:GetMouse()

tool.Activated:Connect(function()
	remote:FireServer(mouse.Target)
end)

If anyone can help me out, please let me know!
Thanks!

EDIT: Reason why I did “velocity.Velocity = Vector3.new(-100,0,0)” was because I was playing around with it.

The issue that I could see (from your video and your code) is that you apply force on the x-axis. To move a model forward/backward, the BodyVelocity must utilize the z-axis aspect of its Velocity property, in which case, your script would look like this:

local tool = script.Parent

local remote = tool:WaitForChild("BlastEvent")

remote.OnServerEvent:Connect(function(player, target)
	if target then
		if target.Parent:FindFirstChild("Humanoid") then
			local root = target.Parent.HumanoidRootPart
			local velocity = Instance.new("BodyVelocity")
			velocity.MaxForce = Vector3.new(6000,6000,6000)
			velocity.Velocity = Vector3.new(0,0,100) -- 0,0,100 moves the zombie backwards, while 0,0,-100 moves it forwards
			velocity.Parent = root
			wait(0.5)
			velocity:Destroy()
		end
	end
end)

This makes a LOT of sense. Tomorrow I’ll try it out when I can.
Thank you!

To move any instance along the Z axis a force must be exerted on the instance similarly along the Z axis.

Vector3.new(math.huge, math.huge, math.huge)

You may also want to use the above to test with, then decrease down to a level which is suitable.

I know it’s been a bit, but I’ve finally gotten to doing it.

However, when I turn one way, it works, but when I turn the opposite way, it goes backwards.

Sorry for bumping this 8 months later, but you can fix that by doing this instead:

velocity.AssemblyLinearVelocity = (root.CFrame.LookVector * 100)
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.