What is the best way to get the 3D position of the mouse?

Hello all,

I am currently making a magic game, and all is going well, however I have run into a slight problem. Whenever I’m making a projectile, I set it’s velocity (Using a LinearVelocity) to mouse.Hit.LookVector * (Insert Number here), but the projectile never really seems to go where you want it to. Don’t get me wrong, the projectile moves towards the mouse, but it isn’t very accurate and I feel like there is a better way to do this.

How would you go about getting the accurate 3D position/LookVector of the mouse? Thank you for your time, and sorry if this explanation was kind of confusing.

LookVector is just a direction unit vector, in this case it’s the looking direction of the mouse’s position in the game world, making this not the correct solution for sending an object to the direction of the mouse.

To create a new direction to assign as the velocity of the bullet, to send it in the direction of the mouse, you can use the following:

local dir = (mouse.Hit.Position - ORIGIN_POSITION_OF_WEAPON).Unit * POWER

--//set the bullet's velocity to dir

Hopefully this is what you want, if I did not understand your question please let me know :slight_smile:

I was thinking of doing that, I will try it out now, thanks!

1 Like

That works surprisingly well! I have been calculating the direction with mouse.Hit.LookVector for years now lol. Thank you very much!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.