look at player and target Code + Explanation

View previous topic View next topic Go down

look at player and target Code + Explanation

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

Camera shown in vid


Code:
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);
      else 
         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.
avatar
InfinitasImpetum
(0%)-Lv8
(0%)-Lv8

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

View user profile

Back to top Go down

View previous topic View next topic Back to top


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