Quantcast
Channel: Latest Questions by Pinsukka
Viewing all articles
Browse latest Browse all 13

Problems with LookAt (C#)

$
0
0
I have a problem with LookAt. I have some gameobjects (each have sprite renderer) and these gameobjects are childs of another gameobject. I need to make the sprites face towards the movement direction, so I turned the child objects 90 degrees in Y and Z axis (so that they turn correctly), then I added a script to the parent that handles the movement and rotation with LookAt like so: transform.LookAt (GameManager.planetPos [target]); transform.position = Vector3.MoveTowards (transform.position, GameManager.planetPos [target], Time.deltaTime * 5.0f); The code is simple and everything seemed to work well, until I noticed something weird. When I set the target directly above or below (in Y axis) the gameobject the sprites disappear. The parent gameobject flips to the wrong direction for some reason causing the sprites to disappear, but this only happens when the target is exactly above or below the gameobject in Y axis. I can kind of fix this issue by moving the target by a minimal amount (like 0.001f so the player won't notice it), but I don't like to fix the problem this way as this issue could potentially cause me many problems in the future. Does anybody have any idea what is going on here?

Viewing all articles
Browse latest Browse all 13

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>