4DIS - Character Controllers

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
Line 16: Line 16:
 
function Update ( )
 
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.buttonUp ) )
 +
        motion.z = speed;
 +
    else if ( Input.GetKey ( input.buttonDown ) )
 +
        motion.z = - speed;
 +
    else
 +
        motion.z = 0;
 
      
 
      
 
     rigidbody.velocity = Vector3.Lerp ( rigidbody.velocity, motion, Time.deltaTime * force );
 
     rigidbody.velocity = Vector3.Lerp ( rigidbody.velocity, motion, Time.deltaTime * force );
 
}
 
}
 +
 +
class
  
 
</javascript>
 
</javascript>

Revision as of 16:00, 29 October 2011

Character Controllers


Roll a ball :

<javascript>

@script RequireComponent ( Rigidbody )

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

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.buttonUp ) )
       motion.z = speed;
   else if ( Input.GetKey ( input.buttonDown ) )
       motion.z = - speed;
   else
       motion.z = 0;
   
   rigidbody.velocity = Vector3.Lerp ( rigidbody.velocity, motion, Time.deltaTime * force );

}

class

</javascript>

Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox