Mouse lookVector not working

I’m trying to send a sphere the direction the mouse is pointing, here are the scripts:

Local Script:

-- Player
local plr     = game.Players.LocalPlayer
local char    = plr.Character
local hum     = char.Humanoid
local dmg     = plr.PlayerDamage
local kiDmg   = plr.PlayerKiDamage
local mouseLv = plr:GetMouse().Hit.lookVector

Then I fire a a ServerEvent

kiBlastEvent:FireServer(kiDmg, mouseLv)

Server Script:

blast.Velocity = mouseLv * 100

But this is what happens when I test it: https://gyazo.com/575e912e28bcdc50a0ce7e56e643e40e

It only goes in one direction, and it is not the direction which the mouse is pointing to.

4 Likes

Because you’re getting the LookVector of the part the mouse is hitting, try Mouse | Documentation - Roblox Creator Hub ?

if not try UnitRay, however, I don’t know much about Rays… :slight_smile:

It’s probably because you didn’t normalize it (put a .Unit after LookVector.) But you might have better success with a formula like this:

local velocity = (blast.Position - mouseLv.Hit.p).Unit * POWER
--//set velocity here

Wait a second, I’m testing all your ideas

does not work, same thing, it randomly selects a direction, and only shoots to that direction
(30 characterss)

If you’re sending a projectile, just send over the mouse.Hit.p. Then once you do that, set the sphere’s CFrame infront or on your humanoidrootpart. After that, set the CFrame again but use the CFrame.new(sphere.Position, mouse.Hit.p), so It looks at your mouse. Lastly, create a BodyVelocity and set the velocity to the lookVector of the sphere.

1 Like

I tried everything still does not work

is this what you meant?

bv.Velocity = CFrame.new(blast.Position, mouse).lookVector * 100

(mouse is a variable equal to mouse.Hit.p)

I fixed it by using

bv.Velocity = CFrame.new(plr.Character.HumanoidRootPart.Position, mouse).lookVector * 100

and instead of creating a variable equal to mouse.hit.p, I passed it as a parameter

That shouldn’t work becuase your using lookVector on a CFrame?

(4 years later damn…) All CFrames have a look vector property, that way you can use it to set velocity

sorry sorr - im stupid idk what i was saying i was tired - glad to see ur still scrpiting 4 years later. Hope youve made progress :+1:

You’re good don’t worry. And yeah, I never stopped, I’m wayyyy better than when I posted this :sob: Honestly glad you replied to this, was funny to see how bad I was.

LOL i feel u - i do have a question though - when you use a mouse for a projectile , if they zoom hella far out their mouse becomes inaccurate as hell - and its a combat agime so some people like to zoom out- do u know a better way to detect the projectile direction because this is proving to be very annoying