Launching a part to an exact Vector3 value

Hello, DevForum!

What I want to make is super simple: make a tool that shoots a random part at a location.

No raycasts or tweens, should purely be using BodyVelocity's or other body movers.


	local mouseHitDirection = mouse.Hit.LookVector
	-- yes, I am instancing the part on the client
	-- i will translate to server soon, just doing this for now
	local part = Instance.new("Part")
	part.Parent = workspace
	part.Position = tool.Handle.Position + Vector3.new(3, 0, 0)
	
	local mover = Instance.new("BodyVelocity")
	mover.Parent = part
	mover.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
	mover.Velocity = mouseHitDirection * 100


Is my current code, but right now, shooting behind the player is impossible. This is a super simple task but after a while of research I couldn’t find anything that can remotely help. I’ve been scripting for a while, so I feel kinda dumb for asking a very simple question, but I am just wondering.

TL;DR - How to send a part to a Vector3 point using BodyVelocity/Other body movers.

If you’d like an arc of some sort, then I recommend taking a look at this tutorial.

Otherwise, you can get a direction by subtracting a destination by the current position, then using the .Unit property of the difference and multiplying it by whatever number you deem fit. I’ll use 100 for this example.

Just think of Vector3.Unit as a sort of LookVector, but just for Vector3’s.

local mouseHitPosition = mouse.Hit.Position
-- yes, I am instancing the part on the client
-- i will translate to server soon, just doing this for now
local part = Instance.new("Part")
part.Parent = workspace
part.Position = tool.Handle.Position + Vector3.new(3, 0, 0)

local mover = Instance.new("BodyVelocity")
mover.Parent = part
mover.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
mover.Velocity = (mouseHitPosition - part.Position).Unit * 100; --100 is how strong it is, feel free to adjust this however you'd like
3 Likes

Wow thanks!

I will need this in the future, so thanks for that :slight_smile:

1 Like