Hi, I’m trying to make my projectiles go exactly to the Mouse.Hit position, but for some reason Its Not going exactly to the mouse, why is this happening?
It works, but its not accurate, I’m not sure how showing rest of the script will help? this is basically the only thing that determines the mouse position, other then that, I just define the mouse.
So first of all, you’re aiming at the skybox so the cursor doesn’t really ‘hit’ anything and as such it will aim at a position an unspecified distance away. I’m not really sure what you’re doing since mouse doesn’t have a LookVector property anyways, but the direction from the object’s position to the mouse’s position (i.e. the direction it needs to fly) is mouse.Hit.p - object.Position.
Maybe try this? You could try setting the CFrame of the Projectile in relation to where the part first spawns and where the Mouse hits, then multiplying it by how fast you want it to go:
local Speed = 80
local Trajectory = CFrame.new(HumanoidRootPart.Position, mouse).LookVector
BodyVelocity.Velocity = Trajectory * Speed
Idk this is what I remember from projectiles, and it seems to work for some reason
You are not wrong, but it is more efficient to do this. If you do it this way, it doesn’t waste resources coming up with a rotation matrix just so you can get a direction.
local Speed = 80
local Trajectory = (mouse-HumanoidRootPart.Position).Unit
BodyVelocity.Velocity = Trajectory * Speed
It looks like you’re attempting to compare a CFrame value, when you should be getting the Mouse.Hit.Position instead in order to obtain a Vector3 value
Both of our codes should work fine, it’s just that you have to change what you’re passing from the client to the server (Or your Mouse.Hit, which is a CFrame)
I believe mine & Jarod’s code were expecting the Mouse to be a Vector3 value when it was passed onto the server, but instead it ended up as a CFrame value which resulted in that error
EDIT: Yeah it works now. Thanks for the help @JarodOfOrbiter and @Jackscarlett. I really appreciate it, I have had this problem now for a while, Thanks!