Winz00e (ver 6.0)
Would you like to react to this message? Create an account in a few clicks or log in to continue.

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 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.
InfinitasImpetum
InfinitasImpetum
(0%)-Lv8
(0%)-Lv8

Posts : 2162
Join date : 2012-05-30
Age : 34

Back to top Go down

Back to top

- Similar topics

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