Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 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 /
  • Help Room /
avatar image
0
Question by DoomPriestK · Nov 30, 2019 at 06:46 PM · unity 2dcodepageisgrounded

isGrounded not working

I have 2 characters running off the following script, they both have gravity scales of 3, both players drop and touch the ground but one bounces back up to his start location, then falls a second later triggering both his AND the other player's jump animation......i've checked all the box and circle colliders and none of them seem to be a bouncy material. Am I missing something?

using System.Collections; using System.Collections.Generic; using UnityEngine;

public class PlayerController : MonoBehaviour {

 public float moveSpeed;
 public float jumpForce;

 public KeyCode left;
 public KeyCode right;
 public KeyCode jump;
 public KeyCode throwNut;

 private Rigidbody2D theRB;

 public Transform groundCheckPoint;
 public float groundCheckRadius;
 public LayerMask whatIsGround;

 public Transform CeilingCheck;
 
 public bool isGrounded;
 private bool isCrouched;
 private float crouch;
 public bool crouching;
 
 private Animator anim;

 public GameObject throwingNut;
 public Transform ThrowPoint;
     
 // Start is called before the first frame update
 void Start()
 {
     theRB = GetComponent<Rigidbody2D>();
     anim = GetComponent<Animator>();
     
 }

 // Update is called once per frame
 void Update()
 {

     isGrounded = Physics2D.OverlapCircle(groundCheckPoint.position, groundCheckRadius, whatIsGround);
     isCrouched = Physics2D.OverlapCircle(CeilingCheck.position, groundCheckRadius, whatIsGround);

     crouch = Input.GetAxisRaw("CrouchInput");
     CrouchFunction();
     GetComponent<Animator>().SetBool("Crouch", crouching);

     if(Input.GetKey(throwNut))
     {
         GameObject nutClone = (GameObject)Instantiate(throwingNut, ThrowPoint.position, ThrowPoint.rotation);
         nutClone.transform.localScale = transform.localScale;
         anim.SetTrigger("Throw");
     }
     if (Input.GetKey(left))
     {
         theRB.velocity = new Vector2(-moveSpeed, theRB.velocity.y);
     }
     else if (Input.GetKey(right))
     {
         theRB.velocity = new Vector2(moveSpeed, theRB.velocity.y);
     }
     else
     {
         theRB.velocity = new Vector2(0, theRB.velocity.y);
     }
     if (Input.GetKeyDown(jump) && isGrounded)
     {
         theRB.velocity = new Vector2(theRB.velocity.x, jumpForce);
     }
     if (theRB.velocity.x < 0)
     {
         transform.localScale = new Vector3(-1, 1, 1);
     }
     else if(theRB.velocity.x > 0)
     {
         transform.localScale = new Vector3(1, 1, 1);
     }
     anim.SetFloat("Speed", Mathf.Abs(theRB.velocity.x));
     anim.SetBool("Grounded", isGrounded);
     
 }
 void CrouchFunction()
 {
     if((crouch!=0 || isCrouched==true) && isGrounded == true)
     {
         crouching = true;
         moveSpeed = 1.5f;
     }
     else
     {
         crouching = false;
         moveSpeed = 6f;
     }
  
 }

}

Collider Controller Script:

using System.Collections; using System.Collections.Generic; using UnityEngine;

public class ColliderControl : MonoBehaviour { public BoxCollider2D stand; public BoxCollider2D crouch; public CircleCollider2D circle;

 PlayerController playerC;

 // Start is called before the first frame update
 void Start()
 {
     playerC = GetComponent<PlayerController>();
     stand.enabled = true;
     crouch.enabled = false;
     circle.enabled = true;
 }

 // Update is called once per frame
 void Update()
 {
     if(playerC.isGrounded == false)
     {
         stand.enabled = true;
         crouch.enabled = false;
         circle.enabled = true;
     }
     else
     {
         if(playerC.crouching == true)
         {
             stand.enabled = false;
             crouch.enabled = true;
             circle.enabled = true;
         }
         else
         {
             stand.enabled = true;
             crouch.enabled = false;
             circle.enabled = true;
         }
     }
 }

}

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

190 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

Related Questions

Update and Get PlayerPrefs during runtime? 0 Answers

Reversing the process 0 Answers

NullReferenceException: Object reference not set to an instance of an object AnimationController.Update () (at Assets/Scripts/AnimationController.cs:17),Can anyone help me? 0 Answers

My Raycast won't work at all ?? (C# Windows) 1 Answer

hi, please help with camera control on android phone 0 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