Hello, this is my first post. I apologize if it is in the wrong section or if the question has already been answered (I checked).
Here is my code:
void Update ()
{
//get positon of mouse and player
Vector2 mousePosition = Camera.main.ScreenToWorldPoint(new Vector2(Input.mousePosition.x, Input.mousePosition.y));
Vector2 playerPosition = new Vector2(player.transform.position.x, player.transform.position.y);
//making the laser
Debug.DrawRay(playerPosition, mousePosition, Color.red, (1f/60f));
}
I am trying to Raycast a ray from the player (using its Transform.Position) to the mouse (using Camera.main.ScreenToWorldPoint).
Ideally, there should be a red line from the middle of the player to the exact mouse positon, no matter where the player or the mouse is.
It works fine when the player is at 0,0 on the coordinate plane: (The black dot is where the mouse is)
But when the player is somewhere else, there’s a strange offset. The ray doesn’t end up at the position of the mouse. It pretends as if the player is at 0,0.
I wrote the code so that the line would end up at the mouse position. So why isn’t it working?
I suspect it has something to do with the orthographic camera.