- Home /
Why am I not moving forward?
So I have a character with a character controller on it, animation is working which is great, however I'm not moving forward, why? =[
Thanks in advance.
 private var equip : int;
 
 var apple : Rigidbody;
 var poisonBerry : Rigidbody;
 
 static var Roses : int;
 private var RosesGathered : boolean;
 private var GrannyDead : boolean;
 
 
 
 function Update () {
 
     if (Input.GetKeyDown("w"))
     {
 
         var controller : CharacterController = GetComponent(CharacterController);
         
         if (controller.isGrounded)
             { 
             moveDirection = Vector3(Input.GetAxis("Horizontal"), 0,
                                     Input.GetAxis("Vertical"));
             moveDirection = transform.TransformDirection(moveDirection);
             moveDirection *= walkSpeed;
             }
             
             controller.Move(moveDirection * Time.deltaTime);    
 
         
         
     
         animation.Play("walk");
     
     }
     
     
     
     if (Input.GetKeyDown("g"))
     {
         var BaitSpawn : GameObject = gameObject.FindWithTag("baitSpawn");
         var BaitThrow = Instantiate(apple,BaitSpawn.transform.position, BaitSpawn.transform.rotation);
         
         
         animation.Play("throw");
         BaitThrow.rigidbody.AddRelativeForce(Vector3.forward * 750);
         
     
     }
 
 
     if (Roses > 9){
     
     RosesGathered = true;
         
     }
     
 }
 
 function OnControllerColliderHit (hit : ControllerColliderHit){
     
     if(hit.gameObject.tag == "GranniesExit"){
     
     Application.LoadLevel(0);
         
     }
 
     if(hit.gameObject.tag == "GranniesDoor"){
         
         if (RosesGathered == true){
         
     Application.LoadLevel(1);
             
             GrannyDead = true;
 
             
         //else{show message - granny would really like some roses}
             
         }
             
     }
 
 
     if(hit.gameObject.tag == "Rose"){
     
     Destroy(hit.gameObject);
     //audio.clip = pickUp;
     //audio.volume = 1.0;
     //audio.Play();
     Roses += 1;
 
     }
     
     
     if(hit.gameObject.tag == "Forest1"){
         
         if(GrannyDead == true){
         
         Destroy(hit.gameObject);
             
         }
         
     }
     
 }
Answer by HunterKrech · Mar 01, 2013 at 06:38 AM
Everything seems right, unless isGrounded never returns true. Test it, at this to Update function.
print(controller.isGrounded); 
Came up false, feel dumb now D: So now I need to implement gravity to this? I'm aware that the character motor script does this but I want to have a go. Anyone suggest how I go about it?
 var grounded : boolean;
 
 if(Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.Space) && grounded == true)
 {
 Jump();
 }
 
 Jump()
 {
 //Jump stuff... addforce or whatever
 grounded = false;
 }
 
 function OnCollisionEnter(collision : Player)
 {
 if(Player.gameObject.tag == ground) //tag ground "ground"
 {
 grounded = true;
 }
 }
basic pseudo code.
Your answer
 
 
             Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
I need to have a player controlled by a controller for a game i am making. 0 Answers
Character controller jittering up and down 2 Answers
Character movement relative to both camera and transform 2 Answers
CharacterController NullReferenceException dispite attached to object 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                