Tuesday, April 9, 2013

Coding Superpowers


#pragma strict
 var player = GameObject.Find("rockman");
 var speed =  0.001;
 var isGrounded : boolean;
 var ballRoll : boolean = false;

         function Update ()
         {
   var characterController = GetComponent(CharacterController) as CharacterController;  
       
    if(Input.GetKey("down") || Input.GetKey("s") && characterController.isGrounded)
    { 
    ballRoll = true;
    characterController.height = 0.00001;
    characterController.center = Vector3(0,0,0);
    characterController.radius = 0.011;
      }
    
    else if((ballRoll == true) && (Input.GetKey("up") || Input.GetKey("w")))
    {
    player.transform.Rotate(0, Time.deltaTime, 0, Space.World);
    player.transform.Translate(0, 1, speed);
    //Move the object upward in world space 1 unit/second.
    player.transform.Translate(0, speed, 0, Space.World); 
    characterController.height = 0.038;  
    characterController.center = Vector3(0,0,0);
    characterController.radius = 0.006;
    ballRoll = false;
       } 
      

Me and Dakota made this code from scratch and we had a million errors with it at first but we finally fixed everything. I'm surprised that the script turned out so well, now our issue is with the animation for this superpower. So, it seems like Codecademy actually taught me a ton of javascript because I completely understand this script, it's awesome. :D

No comments:

Post a Comment