4DIS - Character Controllers

From Unify Community Wiki
Jump to: navigation, search

Character Controllers

4D IS - Back


Roll a ball :

<javascript>

@script RequireComponent ( Rigidbody )

public var speed : float = 5.0; public var force : float = 7.5;

public var input : RollABallInput = new RollABallInput ( );

private var motion : Vector3 = new Vector3 ( 0, 0, 0 );

function Update ( ) {

   if ( Input.GetKey ( input.buttonUp ) )
       motion.z = speed;
   else if ( Input.GetKey ( input.buttonDown ) )
       motion.z = - speed;
   else
       motion.z = 0;
   
   if ( Input.GetKey ( input.buttonRight ) )
       motion.x = speed;
   else if ( Input.GetKey ( input.buttonLeft ) )
       motion.x = - speed;
   else
       motion.x = 0;
   
   motion.y = rigidbody.velocity.y;
   
   rigidbody.velocity = Vector3.Lerp ( rigidbody.velocity, motion, Time.deltaTime * force );

}

class RollABallInput {

   function RollABallInput ( ) { }
   
   public var buttonUp : String = "";
   public var buttonLeft : String = "";
   public var buttonDown : String = "";
   public var buttonRight : String = "";

}

</javascript>

Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox