4DIS - Character Controllers

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
m (Text replace - "<javascript>" to "<syntaxhighlight lang="javascript">")
m (Text replace - "</javascript>" to "</syntaxhighlight>")
 
Line 49: Line 49:
 
}
 
}
  
</javascript>
+
</syntaxhighlight>

Latest revision as of 20:52, 10 January 2012

[edit] Character Controllers

4D IS - Back


Roll a ball :

@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 = "";
}
Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox