Quantcast
Viewing all articles
Browse latest Browse all 133

[SOLVED] How to LookRotation in only Y axis

Hi guys, I'm 4-5 days since started unity noob and I'm just making a game, the problem is that I want to program the **movement** for the camera what just look with smooth movement at the Player, and when I test the game the Camera goes crazy when I move the player trying to just move the camera in the **Y-Axis**, so this is the code that I have so far: Vector3 lookDirection = transform.position - normalCamera.transform.position; Quaternion rot = Quaternion.LookRotation(lookDirection); rot.x = 15.0f; rot.z = normalCamera.transform.rotation.z; normalCamera.transform.rotation = Quaternion.Slerp(normalCamera.transform.rotation, rot, turnSpeed * Time.deltaTime); I tried a lot of posts in this forum but I didn't find a direct solution for the problem, I repeat that I'm a unity noob so I can't find the problem, thank for anyone that could help me Edit: I solved my problem, so I'll put the code that I got and it worked nice. Vector3 lookDirection = transform.position - normalCamera.transform.position; Quaternion rot = Quaternion.LookRotation(Vector3.up+lookDirection); Quaternion rot2 = Quaternion.Euler(0f, rot.y*48.0f, normalCamera.transform.eulerAngles.z); normalCamera.transform.rotation = Quaternion.Slerp(normalCamera.transform.rotation, rot2, turnSpeed * Time.deltaTime);

Viewing all articles
Browse latest Browse all 133

Trending Articles



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