- Home /
Raycast Mouse Position To vector3
so I am trying to do a raytrace position, to wherever my mouse is at the given second. I am kind of a noob so I do not know where to start. I want the ray to get the mouse position, and mark it in a vector3. I want a spawned projectile to move towards the raytraced position anyone have any ideas?
Answer by Joyrider · Feb 09, 2015 at 10:17 AM
You have to use the Physics.Raycast
In the scripting reference, you can fin the 4th overload for the function that has a usage example.
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit, 100))
Debug.DrawLine(ray.origin, hit.point);
From what I understand, hit.point contains the position you want your projectile to move towards.
Your answer
Follow this Question
Related Questions
Problem With Raycasthit Angle 0 Answers
Only One LineRenderer Renders 0 Answers
Raycast detects box collider, but not capsule collider 0 Answers
Boxcast vs Raycast Oddities 1 Answer
Detect Mouse in right side or left side For Player? 2 Answers