Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 /
avatar image
0
Question by Ukeman11 · Jan 16 at 04:48 AM · unity 2dplatformer

character can jump, then isnt able to when I walk. Unity 2d

So here's the problem. I start the game up, and it's fine, my character can run and jump willy nilly. But then after a couple seconds of playing, the character can barely jump while its running, only jumping half the time. Idk what's happening, but if anyone could find potential flaws in my code that might be contributing to this, help would be appreciated. The scripts below are my movement and ground check scripts. also bear in mind that I do have walking animations and idle animations implemented, but I turned them off and it didn't do anything.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class Move2D : MonoBehaviour
 {
     public float moveSpeed = 5f;
     public bool isGrounded = false;
     public bool currentjc = false;
     public Animator animator;
     public float cs;
     
 
 
 
     private void FixedUpdate()
     {
        
     }
     // Update is called once per frame
     void Update()
     {
         jump();
         Vector3 movement = new Vector3(Input.GetAxis("Horizontal"), 0f, 0f);
         transform.position += movement * Time.deltaTime * moveSpeed;
         animator.SetFloat("playerSpeed", Mathf.Abs(Input.GetAxis("Horizontal") ));
         cs = Input.GetAxis("Horizontal") * moveSpeed;
 
         
     }
 
     void jump()
     {
         if (Input.GetButtonDown("Jump") && isGrounded == true )
         {
             gameObject.GetComponent<Rigidbody2D>().AddForce(new Vector2(0f, 100.5f), ForceMode2D.Impulse);
            
            
            
         }
 
 
     }
 }
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class gc : MonoBehaviour
 {
     GameObject Player;
    
     void Start()
     {
         Player = gameObject.transform.parent.gameObject;
     }
 
 
     private void OnCollisionEnter2D(Collision2D collision)
     {
         if (collision.collider.tag == "Ground")
         {
             Player.GetComponent<Move2D>().isGrounded = true;
            
         }
     }
     private void OnCollisionExit2D(Collision2D collision)
     {
         if (collision.collider.tag == "Ground")
         {
             Player.GetComponent<Move2D>().isGrounded = false;
 
         }
     }
     
 }
 

Here is an unlisted youtube video showing off the problem. https://youtu.be/DWEoyY2UU0c Any help is appreciated!

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 DTheChemist · Jan 16 at 09:13 AM

the Is_Grounded is part of the ground check detection public bool of mines. Just adjust your own

void Update() {

if (Input.GetButtonDown("Jump") && Is_Grounded()) {

             Jump();
         }

}

void Jump() { Vector2 movement = new Vector2(rb.velocity.x, jumpForce);

         rb.velocity = movement;

     }
Comment
Add comment · 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.

Follow this Question

Answers Answers and Comments

145 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

Related Questions

2D platformer - character clips into the ground 1 Answer

How do I get my character to dash up? 0 Answers

Why does my sprite change size when in game but not when in scene? 0 Answers

2D Platformer - How do I have objects that kill the player upon touch/cause respawn? 2 Answers

unity 2d how to make grappling hook 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