Quantcast
Channel: Questions in topic: "around"
Viewing all articles
Browse latest Browse all 101

Rotating camera around object up/down problem

$
0
0
Hey everyone! Ive been into unity3d for a few days now, ive browsed through several Q&A posts and havent found solution to this yet. What im trying to do is make the main camera orbit around player when pressing WASD keys. A and D are working perfectly fine, but W and S are having problems, the camera starts to rotate very weirdly when pressing them. Its hard to describe the movement that camera makes, but i think you can find the issue in my code. #pragma strict var Target : Transform; var CameraSpeed = 0.1; var DistanceToPlayer : float; var xRot : float; var MaxX = 55; var MinX = 5; private var point; function Start () { } function Update () { xRot = transform.eulerAngles.x; point = Target.position; if(Input.GetKey(KeyCode.A)){ transform.RotateAround(point,new Vector3(0f,1f,0f), CameraSpeed); transform.LookAt(Target); } if(Input.GetKey(KeyCode.D)){ transform.RotateAround(point,new Vector3(0f,-1f,0f), CameraSpeed); transform.LookAt(Target); } if(Input.GetKey(KeyCode.W) && xRot < MaxX){ transform.RotateAround(point,new Vector3(1f,0f,0f), CameraSpeed); transform.LookAt(Target); } if(Input.GetKey(KeyCode.S) && xRot > MinX){ transform.RotateAround(point,new Vector3(-1f,0f,0f), CameraSpeed); transform.LookAt(Target); } }

Viewing all articles
Browse latest Browse all 101

Trending Articles



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