Question by
Darkforge317 · Nov 02, 2017 at 05:09 AM ·
screenmousepositionnegativeincorrect
ScreenToViewportPoint with MousePosition giving -0.1 instead of 0
Hi!
I was wondering why using Input.MousePosition with ScreenToViewportPoint is giving me -0.1 in x when I move my mouse to the very left of the screen, and -0.1 in y when moving to the very bottom of the screen.
I find it odd as I thought ScreenToViewportPoint only gave mouse coordinates on a 0 to 1 scale.
Why am I getting something lower than 0 and is there a way I can fix this? I have provided my code below in case you notice I'm doing something incorrectly.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraController : MonoBehaviour
{
// Constant reference to mouse position as a screen point
// Check if that reference is on the left, right, top, or down
// and maybe diagonal.
Vector3 mouseScreenPos;
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
mouseScreenPos = GetComponent<Camera>().ScreenToViewportPoint(Input.mousePosition);
}
}
(I would have added line breaks if I knew how to... sorry)
untitled.png
(11.7 kB)
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612142402im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Detect the display of current mouse position (Windows) 1 Answer
Move Object to the side of the Screen 1 Answer
Screen Fader Problem 1 Answer
appear black box on screen unity 1 Answer
Screen Resolution or aspect wrong? 0 Answers