4DIS - Camera Controller

From Unify Community Wiki
Revision as of 06:02, 10 November 2011 by 4D Interactive Studio (Talk | contribs)

Jump to: navigation, search

Camera Controllers

4D IS - Back


Camera Controller A.js

<javascript>

public var target : Transform;

public var positionOffset : Vector3 = new Vector3 ( 0, 0, 0 ); public var rotationOffset : Vector3 = new Vector3 ( 0, 0, 0 ); public var positionForce : float = 5.0; public var rotationForce : float = 5.0;

private var position : Vector3 = new Vector3 ( 0, 0, 0 ); private var rotation : Quaternion = new Quaternion ( 0, 0, 0, 0 );

function Update ( ) { if ( ! target ) return null;

position = Vector3.Lerp ( position, target.position, Time.deltaTime * positionForce ); rotation = Quaternion.Lerp ( rotation, target.rotation, Time.deltaTime * rotationForce );

transform.position = position; transform.rotation = rotation;

transform.Rotate ( rotationOffset, Space.Self ); transform.Translate ( positionOffset, Space.Self ); }

</javascript>

Camera Controller B.js

<javascript>

public static var target : Transform;

public var positionOffset : Vector3 = new Vector3 ( 0, 1, 4 ); public var positionForce : float = 5.0; public var lookFactor : float = 0.3; public var lookForce : float = 0.6;

private var position : Vector3 = new Vector3 ( 0, 0, 0 ); private var rotation : Vector3 = new Vector3 ( 0, 0, 0 );

function Update ( ) { if ( ! target ) return null;

if ( positionForce > 0 ) position = Vector3.Lerp ( position, target.position, Time.deltaTime * positionForce ); else position = Vector3 ( 0, 0, 0 );

if ( target.rigidbody ) rotation = Vector3.Lerp ( rotation, target.rigidbody.velocity * lookFactor, Time.deltaTime * lookForce );

transform.rotation = Quaternion ( 0, 0, 0, 0 );

transform.position = position; transform.Translate ( positionOffset, Space.Self );

transform.LookAt ( target.position + rotation ); }

</javascript>

Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox