• 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 /
  • Help Room /
avatar image
Question by Sir-G · Apr 10, 2017 at 04:03 AM · movementjumpjumpingjumping objectobject movement

Player looses ability to jump further right player moves.

Ok so I have my PlayerMovement controller going and have the character moving left and right, jumping, and double jumping. However after the character begins moving to the right the jumps get shorter and shorter. By the time you get to the 10th tile you no longer are able to jump at all. Any ideas on what this could be? There are no collision blocks causing it and none of the surrounding elements except the ground are considered solid.

Here is my PlayerMovement script

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class PlayerMovement : MonoBehaviour {
 
     public Transform playerTransform; //Player movement
     public Rigidbody2D playerRigidBody; //Player jump
     public int speed; //Controls how fast the character can move
     //public int jumpHeight = 5;
     private bool isFalling = false; //Check for character falling
     //public Vector2 resetJumpHeight = new Vector2(0, 0); //Sets the jump height and locks it to where it only transforms the Y axis
     public Vector2 jumpHeight = new Vector2(0, 15); //Sets the jump height and locks it to where it only transforms the Y axis
     public bool isDoubleJumping = false;
     public bool isOnGround = true; //Check if character is on the ground or in the air
 
     private Animator myAnimator;
     public int jumpCount = 0;
     // Use this for initialization
     void Start () {
         playerTransform = GetComponent<Transform>();
         playerRigidBody = GetComponent<Rigidbody2D>();
         myAnimator.GetComponent<Animator>();
     }
     
     // Update is called once per frame
     void Update () {
         //Move Player Right
         if (Input.GetKey(KeyCode.D))
         {
             playerRight();
         }
         //Move Player Left
         else if (Input.GetKey(KeyCode.A))
         {
             playerLeft();
         }
         //Player Jump
         else if (Input.GetKey(KeyCode.Space))
         {
             playerJump();
         }else if (Input.GetKeyUp(KeyCode.Space))
         {
             if (jumpCount != 3)
             {
                 jumpCount = jumpCount + 1;
             }
         }
     }
 
     //Move Player Right
     void playerRight()
     {
         playerTransform.Rotate(Vector2.right * speed * Time.deltaTime);
         playerTransform.Translate(new Vector2(speed, 0) * Time.deltaTime);
         //Player Jump while Moving Right
         if (Input.GetKey(KeyCode.Space))
         {
             playerJump();
         }
     }
     //Move player Left
     void playerLeft()
     {
         playerTransform.Rotate(Vector2.left * speed * Time.deltaTime);
         playerTransform.Translate(new Vector2(-speed, 0) * Time.deltaTime);
         //Player Jump while Moving Right
         if (Input.GetKey(KeyCode.Space))
         {
             playerJump();
         }
     }
     //Player Jump
     void playerJump()
     {
 
         if (isOnGround == true)
         {
             playerRigidBody.velocity = jumpHeight;
             isOnGround = false;
         }
 
         if (isOnGround == false && jumpCount == 1)
         {
             //playerRigidBody.velocity = resetJumpHeight;
             playerRigidBody.velocity = (playerRigidBody.velocity + (jumpHeight + jumpHeight));
             jumpCount = 3;
             isDoubleJumping = true;
         }
         else
         {
             
         }
         
     }
 
     //Test for ground collision
     private void OnCollisionEnter2D(Collision2D collision)
     {
         isOnGround = true;
         isDoubleJumping = false;
         jumpCount = 0;
     }
 }
 
Comment

People who like this

0 Show 0
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

Answer by Sir-G · Apr 10, 2017 at 04:41 AM

Well come to find out in a 2D game you need to make sure the Animator has Apply Root Motion not checked or else the physics gets funky the further right you move in the play field.

Comment

People who like this

0 Show 0 · 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

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

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

118 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

My jump scripit wont work. i have been tryingtt o make it work for an eternity. please help. 1 Answer

How i make a ball jump where i point with my mouse?[3D] 0 Answers

How to put delay after input key 0 Answers

Jump Script Not Working 1 Answer

Jumping higher the more you hold space! 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges