RedditPP Mascot

RedditPP

r/unity • … • u/D3vil_Dant3

fix for "Look rotation viewing vector is zero"

Hello there, i've written a simple script for player movement, with a "Look" method to rotate the character accordingly to the mouse position. The camera used is tilted for an isometric 3d game i'm working on (35° along x, and 45° along y, with the z position on -80). Despite everything works as intended, every time i run play, the "look rotation viewing vector is zero" is spammed into the console. The script i'm using is this:

[`https://pastebin.com/ZwUB2k4D`](https://pastebin.com/ZwUB2k4D)

Do you have any idea what's the zero vector? i check everything but never get rid of it. And, i thought checking looDir.sqrMagnitude would be enough. Maybe is something about the raycast? It's frustrating cause i can't debug the allert.

Thanks for help

edit: replace with pastebin edit2: added a check for raycasting:

edit3: i overlooked so much the Look() function that i forgot to check the rest of the code. The allert was risen by the Move() method--> i did normalize before checking if the vector was different from zero.

Solved!!

if (plane.Raycast(ray, out float distance)) { _mousePos = ray.GetPoint(distance); } else { return; }

— 0