My bullet not going exact direction and also spawning in random place when clicked on skybox

So here when I left click, it Instances a bullet 2 studs in front of my HumanoidRootPart. Now I want it to go exactly to the place I but if you see this video you will understand where the problem is:
And also when I am clicking on the skybox the bullet is spawning randomly and not in front of my HumanoidRootPart
note: There might be better ways to perform the task I want to happen but as a quite unexperienced scripter I am learning something new every day and maybe I will learn those ways as well and it would be really helpful if someone helps me out pointing out my mistakes
My Scripts:

The 3D position of the mouse is not equal to the direction.
You could send the mouse direction to the server instead.
And if you don’t want to do that you could probably do something like this:

local direction = (mousePosition - originPosition).Unit

Good luck!

1 Like

Thanks for the solution!
Actually, I really wanna understand more about the topic of mouse Position and how the direction is getting defined as we subtract and what exactly does the unit do
Yes, I have read the article before asking you but when someone explains it , that seems simpler
If you are free then I would be glad if you can figure some time out to explain the fundamental of how it is working

I learned a lot of vectors from this: The Nature of Code
You can also find his channel on YouTube called “The Coding Train” if you don’t enjoy reading. He explains it quite well. I think it will provide you with at least a basic understanding of vectors.