Skip to content

Instantly share code, notes, and snippets.

@moon-goon
Created January 24, 2016 05:50
Show Gist options
  • Save moon-goon/5feb59dc900adf4e8608 to your computer and use it in GitHub Desktop.
Save moon-goon/5feb59dc900adf4e8608 to your computer and use it in GitHub Desktop.
public GameObject targetObj;
public float rotateSpeed = 2;
Vector3 offsetValue;
void Start() {
offsetValue = targetObj.transform.position - transform.position;
}
void LateUpdate() {
float horizontal = Input.GetAxis("Mouse X") * rotateSpeed;
targetObj.transform.Rotate(0, horizontal, 0);
float initAngle = targetObj.transform.eulerAngles.y;
Quaternion rotation = Quaternion.Euler(0, initAngle, 0);
transform.position = targetObj.transform.position - (rotation * offsetValue);
transform.LookAt(targetObj.transform);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment