Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Projectile not going to where I want it to?

Asked by 5 years ago

I'm trying to make a projectile go towards my mouse's location, but I can't get it to work properly. I'll include part of my script as the entirety of it is quite large.

local mouse = player:GetMouse()
local projectile = game:GetService("ReplicatedStorage"):Clone()
projectile.CFrame = char.LowerTorso.CFrame
local bv = Instance.new("BodyVelocity")
bv.Parent = projectile
bv.MaxForce = Vector.new(math.huge,math.huge,math.huge)
bv.Velocity = mouse.Hit.CFrame * 50 

Any and all help appreciated!

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

First of all, you are never parenting the projectile. Also, to make the BodyVelocity aims towards the mouse's location, you have to use the lookVector property of mouse.Hit.

local mouse = player:GetMouse()
local projectile = game:GetService("ReplicatedStorage"):Clone()
projectile.Parent = workspace -- parent the projectile to workspace
projectile.CFrame = char.LowerTorso.CFrame
local bv = Instance.new("BodyVelocity")
bv.Parent = projectile
bv.MaxForce = Vector.new(math.huge,math.huge,math.huge)
bv.Velocity = mouse.Hit.LookVector * 50 -- use lookVector

Let me know if you have any more questions or need help!

0
It worked thanks! 2052Game 25 — 5y
0
It's LookVector now FYI. User#19524 175 — 5y
0
Okay, wasn't aware of the change. MythicalShade 420 — 5y
Ad

Answer this question