• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Lucifer95 · Aug 03, 2014 at 06:08 PM · jumpinfinite

character not jumping

 #pragma strict
 
     var jumps:AudioClip;
     var stopfoot :AudioSource;
     var speed =40;
     var jumpSpeed : float = 10.0f;
     var controller : CharacterController ;
     var turnSpeed: float = 90; // degrees per second
     private var moveDirection : Vector3;
 
     function Start()
     {
     
      controller= GetComponent(CharacterController);
     
     }
     
     
     function Update() {
     if(Input.GetKeyDown(KeyCode.RightArrow))
       transform.Rotate(0, turnSpeed, 0);
       if(Input.GetKeyDown(KeyCode.LeftArrow))
       transform.Rotate(0, -turnSpeed, 0);
       moveDirection = Vector3(Input.GetAxis("Horizontal")*10, 1,
     speed);
     if (controller.isGrounded)
 {
     if(Input.GetKeyDown(KeyCode.Space))
     {
     moveDirection.y=jumpSpeed;
         Debug.Log("jump");    
     }
     }
     moveDirection *= speed;
     if(!controller.isGrounded)
     {
         moveDirection.y -= 5*Time.deltaTime;
      Debug.Log("gravity");
        }
       controller.SimpleMove(moveDirection * Time.deltaTime);
 }
  
 function jump()  {  
       
          audio.Stop();
          audio.PlayOneShot(jumps);
          animation.Play("jump_pose");
          yield WaitForSeconds(1f);
          animation.Play("run");
         }
         if(transform.position.y<=490)
                 {
             Destroy(this.gameObject);
                 }

tried adding velocity and not using gravity,non of them works. this is an infinite runner,with player moving constantly with rigid body attach to it.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by robertbu · Aug 03, 2014 at 06:29 PM

There code is a real snarl. With respect to the jump, there are two things to check first. Since 'jumpSpeed' is a public variable, check the value in the Inspector. The value in code will only be used when the script is attached. Second, you don't scale 'Time.deltaTime' the value you pass to SimpleMove(). SimpleMove() does deltaTime factoring internally.

Other issues not related to the not-working jump:

  • You set 'z' to 'speed' when you do your arrow key code, but then you again multiply moveDirection by speed on line 34. Remove line 34 and adjust your other values.

  • Lines 51 - 54 are outside of any function.

  • I don't know your intent, but your structure will allow the player to do an immediate change in direction while jumping.

  • I don't know your intent, but because of the way you did your arrow keys, the player cannot move on the diagonal.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Lucifer95 · Aug 04, 2014 at 11:57 AM 0
Share

ok i'll try that

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

Architecture of "doodle jump" type gameplay 1 Answer

jump gets longer after some time 0 Answers

How to make a game with lots of objects?!! 1 Answer

How to make sure that my cube can only jump when in contact with the ground 2 Answers

Path constrained characters. 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges