Created
January 24, 2016 05:50
-
-
Save moon-goon/5feb59dc900adf4e8608 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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