look at player and target Code + Explanation

Go down

look at player and target Code + Explanation Empty look at player and target Code + Explanation

Post by InfinitasImpetum on Fri Jan 02, 2015 4:12 pm

Camera shown in vid

using UnityEngine;
using System.Collections;

public class CameraController : MonoBehaviour {
   public GameObject FollowObject;
   public float FollowDistance;
   // Use this for initialization
   void Start () {
   // Update is called once per frame
   void Update () {
      transform.position = FollowObject.transform.position + FollowObject.GetComponent<Stats> ().centerPoint;
      LookAtTarget ();
      transform.position = transform.position - (transform.forward * FollowDistance);


   void LookAtTarget(){
      if (FollowObject.GetComponent<MechaController>().LockOn) 
         transform.LookAt (FollowObject.GetComponent<MechaController>().Target.transform);
         transform.eulerAngles = FollowObject.transform.eulerAngles;

explanation(best i can do):
 on the update method it places itself at the center point of the folow object determined by follow objects position and follow objects centerpoint(offset). then the camera points itself towards the target object and backs up the distance you want it to follow at. 

script is pretty self-explained, if you don't understand.

Posts : 2160
Join date : 2012-05-30
Age : 29

View user profile

Back to top Go down

Back to top

- Similar topics

Permissions in this forum:
You cannot reply to topics in this forum