Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • 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
0
Question by unity_cCHwdyam0bTBLg · Feb 23, 2020 at 08:05 PM · movement scriptjumpingnot workingcharacter movementhorizontal movement

Jumping disables my horizontal movement.

Hey there, I've recently run into a little problem, whenever I jump my Horizontal movement just stops.. I have no idea when it started happening or what could be causing it, I'm probably just overlooking something extremely obvious or have something somewhere in an If statement that it shouldn't be.. anyways if someone could help or send me in a direction, I have look for solutions and nothing has worked so far..

Here's my entire script, the movement is at the top of the Update, When I add another script that runs AllInOne.GetComponent(); inside the Start void and then save it while my game is running it suddenly works, but as soon as I stop running the game and run it again, I get my ussie of jumping and moving again.. I would also like to point out that while I am falling from the jump I can move perfectly fine, it's only while I am moving upwards.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class AllInOne : MonoBehaviour
 {
 
 
 
     public float inputVertical;
     public Animator playerAnim;
     public Animator cameraAnim;
     public float speed;
     public float moveInput;
     public float jumpTimeCounter;
     public float jumpTime;
     public float jumpForce;
     private bool isJumping;
     public bool isGrounded;
     public bool isClimbing;
     public Transform feetPos;
     public LayerMask whatIsGround;
     public LayerMask whatIsLadder;
     public Rigidbody2D rb;
     public float checkRadius;
     public float GetVerticalSpeed() => rb.velocity.y;
     public float distance;
     //Particles
     public GameObject deathEffect;
     public GameObject landEffect;
 
     //Allow partciles   
     public bool spawnDust;
 
 
 
 
 
 
 
 
 
     // Start is called before the first frame update
     void Start()
     {
         rb = GetComponent<Rigidbody2D>();
     }
 
     // Update is called once per frame
     void Update()
     {
 
         //Movement
         //Horizontal Movement AKA Walking
         moveInput = Input.GetAxis("Horizontal");
         rb.velocity = new Vector2(moveInput * speed, rb.velocity.y);
         playerAnim.SetFloat("Speed", Mathf.Abs(moveInput));
 
         if (moveInput > 0)
         {
             transform.eulerAngles = new Vector3(0, 0, 0);
         }
         else if (moveInput < 0)
         {
             transform.eulerAngles = new Vector3(0, 180, 0);
         }
 
 
 
 
         //Jump
         if (isGrounded == true && Input.GetKeyDown(KeyCode.Space))
         {
             isJumping = true;
             jumpTimeCounter = jumpTime;
             rb.velocity = Vector2.up * jumpForce;
             Instantiate(deathEffect, feetPos.position, Quaternion.identity);
 
 
 
 
         }
         //jump higher but not too high or too long thing
         if (Input.GetKey(KeyCode.Space) && isJumping == true)
         {
             if (jumpTimeCounter > 0)
             {
                 rb.velocity = Vector2.up * jumpForce;
                 jumpTimeCounter -= Time.deltaTime;
 
             }
             else
             {
                 isJumping = false;
 
             }
 
 
         }
 
         isGrounded = Physics2D.OverlapCircle(feetPos.position, checkRadius, whatIsGround);
 
         //Ladder
         RaycastHit2D hitInfo = Physics2D.Raycast(transform.position, Vector2.up, distance, whatIsLadder);
 
         if (hitInfo.collider != null)
         {
 
             playerAnim.SetBool("Jump", false);
             playerAnim.SetBool("IsFalling", false);
             //set gravity to slow slow for when falling down
             rb.gravityScale = 0.01f;
             //when key make gravity 0 and let me move up and down
         }
 
         if (Input.GetKeyDown(KeyCode.W))
         {
             isClimbing = true;
         }
         else
         {
             isClimbing = false;
             rb.gravityScale = 5;
             playerAnim.SetBool("Ninja", false);
 
         }
 
 
         if (isClimbing == true)
         {
             inputVertical = Input.GetAxis("Vertical");
             rb.velocity = new Vector2(rb.velocity.x, inputVertical * speed);
             rb.gravityScale = 0;
 
         }
 
 
 
 
 
             //Animations
             RaycastHit2D ladInfo = Physics2D.Raycast(transform.position, Vector2.up, distance, whatIsLadder);
             if (ladInfo.collider != null)
             {
                 if (GetVerticalSpeed() > 0.1)
                 {
                     playerAnim.SetBool("Ninja", true);
                 }
 
                 if (GetVerticalSpeed() < 0.1)
                 {
                     playerAnim.SetBool("Ninja", true);
                 }
             }
 
             //animation stuff
             if (isGrounded == true)
             {
                 playerAnim.SetBool("Jump", false);
                 playerAnim.SetBool("IsFalling", false);
                 playerAnim.SetBool("Ninja", false);
 
 
             }
             else
             {
 
                 if (GetVerticalSpeed() > 0.1 && isClimbing == false)
                 {
                     playerAnim.SetBool("Jump", true);
                     playerAnim.SetBool("IsFalling", false);
                     cameraAnim.SetBool("can", false);
                 }
 
                 else if (GetVerticalSpeed() < 0.1 && isClimbing == false)
                 {
                     playerAnim.SetBool("IsFalling", true);
                     playerAnim.SetBool("Jump", false);
                     cameraAnim.SetBool("can", true);
                 }
 
                 else if (GetVerticalSpeed() == 0 && isClimbing == false)
                 {
                     playerAnim.SetBool("Jump", false);
                     playerAnim.SetBool("IsFalling", false);
                     cameraAnim.SetBool("can", false);
                 }
             }
 
 
 
 
             
 
 
             //particle
             if (isGrounded == true)
             {
                 if (spawnDust == true)
                 {
 
                     cameraAnim.SetBool("shakywaky", true);
                     Instantiate(landEffect, feetPos.position, Quaternion.identity);
                     spawnDust = false;
                 }
             }
             else
             {
                 spawnDust = true;
                 cameraAnim.SetBool("shakywaky", false);
             }
 
 
     }
 }
 
 
 
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

0 Replies

· Add your reply
  • Sort: 

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.

Follow this Question

Answers Answers and Comments

201 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 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

Character landing 0 Answers

* A simple script where every single time my character jumps it will increase speed *, * A needed script where every time you perform a jump and land your speed increases * 0 Answers

[C#] Can't Control Movement While Jumping 0 Answers

Why is root motion reduced once I apply the animation? 0 Answers

Player flying into oblivion. 2 Answers


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