- Home /
Aim at mouse error
I'm using the following script to aim using the mouse at the screen but sometimes the aim device doesn't follow it and stays looking in the same direction. I believe it's due to the mouse position exceeding the screens height and width positions but I can't be sure...Is there anyway to fix this?
I'm using a cube as the firing point for the shots.
var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
var hit : RaycastHit;
if (Physics.Raycast (ray, hit)) {
AimingTarget = hit.point;
}
transform.LookAt(AimingTarget);
In what situation are you using the mouse ? Is it in a $$anonymous$$imized game window or a maximized one? Is it in a Web Build or other build that uses full screen? These things can cause some issues as I noticed with testing my own code.
Answer by 3dDude · Dec 18, 2010 at 06:20 PM
All I can think of is that the ray is not hitting a collider... you could try adding more colliders to the empty parts of the scene.
hope this helps!
Your answer
![](https://koobas.hobune.stream/wayback/20220613085855im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Mouse Aiming Follow Wrong Direction - Help 2 Answers
how do i make somthing rotate with mouse 1 Answer
Bullets follow mouse after shooting in Sidescroller 1 Answer
Top-Down Mouse aiming help 1 Answer
Aiming With my mouse 1 Answer