- Home /
Inverted editor mouse position raycast
Hi, I'm currently working on a level editor and I'm trying to get the world position of the mouse in the scene view. I'm currently doing the following:
void OnSceneGUI(){
if(Event.current.type == EventType.mouseMove){
ray = Camera.current.ScreenPointToRay(Event.current.mousePosition);
if (Physics.Raycast(ray, out hit,10000,mask)){
GameObject.Find ("Cube").transform.position = hit.point;
}
}
}
It works fairly well, however the z axis seems to react like it's mirror. Meaning if I move my mouse down the object will go up and vice versa. I've tried -hit.point.z in a Vector3 but that results in a weird offset. Does anyone know what I'm doing wrong?
I ran it with Input.mousePosition in runtime which worked fine. Does anyone have any idea why the Scene View camera behaves this way?
Answer by TurboHermit · Nov 25, 2019 at 10:26 AM
By sheer coincidence I stumbled across the same problem 5 years later and found my own question haha. This forum post handles some solutions.
Your answer
Follow this Question
Related Questions
Mouse plane does not detect height 1 Answer
Network - Editor + Builds = Problem with RayCasts? 0 Answers
Raycast hitting below mouse position :( 0 Answers
3rd person 3D aiming 1 Answer