Raycast not drawing where i tell it
I would really appreciate any help on this one.
I am instantiating with raycast and mousePosition. However, there is a difference between the game scene and the editor scene. In the editor scene I can see that the prefab instantiates and moves across the ray correctly, but in the actual game this ray is nowhere near where I actually click in the scene.
My code is:
void Shoot() {
Vector3 mousePosition = playerCamera.ScreenToWorldPoint(Input.mousePosition);
Ray myRay = new Ray(firePoint.position, mousePosition);
RaycastHit hitInfo;
Physics.Raycast(myRay, out hitInfo, fireDistance);
Debug.DrawRay(firePoint.position, mousePosition, Color.red);
Instantiate(knifePrefab, firePoint.position, Quaternion.LookRotation(myRay.direction));
}
and an example of the results are below. Notice the mouse pointer on the bottom corner of the red block. The ray is no where near it.
Your answer
![](https://koobas.hobune.stream/wayback/20220612162503im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
My Ray is going the wrong way 1 Answer
Shoot towards mouse except mouse y 1 Answer
am trying to instantiate a 3D object to fly in the direction where my mouse is pointing 0 Answers
Can't call raycast on plane to get mouse position? Beginner Question 1 Answer
How can I use RayCasting to interact with RigidBodies and Colliders? 0 Answers