SmoothLookFrame

From Unify Community Wiki
Revision as of 02:30, 22 December 2010 by Trooper (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Looks at a target whilst keeping another target in view.

<csharp> using UnityEngine;

public class SmoothLookFrame : MonoBehaviour {

public Transform lookAtTarget; public Transform frameTarget; public float distance = 10.0f; public float height = 5.0f; public float damping = 2.0f;

private Vector3 direction; private Vector3 wantedPosition;

void FixedUpdate () {

if (!lookAtTarget || !frameTarget) return;

direction = (frameTarget.position - lookAtTarget.position);

wantedPosition = frameTarget.position + (direction.normalized * distance); wantedPosition.y = wantedPosition.y + height;

transform.position = Vector3.Lerp(transform.position, wantedPosition, damping * Time.deltaTime);

transform.LookAt (lookAtTarget);

}

}</csharp>

Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox