Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Kyle Rosse](https://secure.gravatar.com/avatar/4521583e96275bb3d9ece9db3c879cef?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Kyle Rosse
11,857 PointsCamera is zooming way far out
Hey everyone, the camera is zooming super far out on the x and z axis when I run this script
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class OrbitCamera : MonoBehaviour {
[SerializeField]
private Transform target;
[SerializeField]
private float rotationSpeed = 10f;
[SerializeField]
private float bobPeriod = 2f;
[SerializeField]
private float bobAmplitude = 2f;
private float startY;
private float bobDistance;
// Use this for initialization
void Start () {
//store the start position of the camera
startY = transform.localPosition.y;
}
// Update is called once per frame
void Update () {
//update the vertical camera bob
bobDistance = Mathf.Sin(Time.timeSinceLevelLoad / bobPeriod) * bobAmplitude;
transform.position = new Vector3 (transform.localPosition.x, startY + bobDistance, transform.localPosition.z);
//update camera position
transform.RotateAround (target.position, Vector3.up, rotationSpeed * Time.deltaTime);
//update the camera look
transform.LookAt (target);
}
}
1 Answer
![Wesley Trayer](https://uploads.teamtreehouse.com/production/profile-photos/8661802/micro_floor_plates_brown.jpg)
Wesley Trayer
13,812 PointsI don't see a mistake. I also ran your code in an already working version of the game and it seemed to run just fine.
Is your "[SerializeField]-target" set to "board"? If it were set to "Directional Light", for instance, it would fly right out of the room. :)
Wesley Trayer
13,812 PointsWesley Trayer
13,812 PointsJust encountered this problem, I removed the script component and then reapplied it. No more problem!
Puzzling.