SmoothLookFrame

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
(New page: Looks at a target whilst keeping another target in view. <csharp> using UnityEngine; public class SmoothLookFrame : MonoBehaviour { public Transform lookAtTarget; public Transform fr...)
 
Line 1: Line 1:
 +
[[:Category:Description]]
 
Looks at a target whilst keeping another target in view.
 
Looks at a target whilst keeping another target in view.
  
<csharp>
+
[[:Category:C# Script]]
using UnityEngine;
+
<csharp>using UnityEngine;
  
 
public class SmoothLookFrame : MonoBehaviour {
 
public class SmoothLookFrame : MonoBehaviour {
Line 32: Line 33:
 
 
 
}</csharp>
 
}</csharp>
 +
 +
[[:Category:Javascript]]
 +
<java>var lookAtTarget : Transform;
 +
var frameTarget : Transform;
 +
var distance : float = 10.0;
 +
var height : float = 10.0;
 +
var damping : float = 2.0;
 +
 +
private var direction : Vector3;
 +
private var wantedPosition : Vector3;
 +
 +
function 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);
 +
}</java>

Revision as of 02:35, 22 December 2010

Category:Description Looks at a target whilst keeping another target in view.

Category:C# Script <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>

Category:Javascript <java>var lookAtTarget : Transform; var frameTarget : Transform; var distance : float = 10.0; var height : float = 10.0; var damping : float = 2.0;

private var direction : Vector3; private var wantedPosition : Vector3;

function 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); }</java>

Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox