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 igothacked092 · May 14 at 08:42 AM · charactercontrollerprogrammingfloatprogramming-basics

problem with ground check

hello, so I have been working on this little project and I am still very new to game development and programming and I have gotten this issue that I can not FIGURE OUT. where I need to put in a float but it wont accept it.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class PlayerController : MonoBehaviour
 {
     private bool isGrounded;
 
     public float jumpForce;
     private Rigidbody rb;
     public float speed;
     private float XInput;
     private float ZInput;
 
     public Transform groundCheck;
     private float radius;
     public LayerMask whatIsGround;
 
     private void Start()
     {
         rb = GetComponent<Rigidbody>();
     }
 
     private void FixedUpdate()
     {
         XInput = Input.GetAxis("Horizontal");
         ZInput = Input.GetAxis("Vertical");
         rb.velocity = new Vector3(XInput * speed, rb.velocity.y, ZInput * speed);
 
         isGrounded = Physics.OverlapSphere(groundCheck.position, radius, whatIsGround); //<-- it wont accept "radius"
 
         if (Input.GetKeyDown(KeyCode.Space) && isGrounded == true)
         {
             rb.velocity = Vector2.up * jumpForce;
         }
     }
 
 }
 

please help

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 BKN_Nahar · May 14 at 09:20 AM

Hey, the problem is pretty simple -- OverlapSphere shows all the colliders it collides with while isGrounded is a bool and thus the code doesnt compile... to get a bool you must use "CheckSphere".. I have attached the script below, you will understand by just going through it ( I havent changed anything except the overlapSphere method, so you can copy paste the whole code without any worries). CODE >>>

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class PlayerController : MonoBehaviour
 {
     private bool isGrounded;
 
     public float jumpForce;
     private Rigidbody rb;
     public float speed;
     private float XInput;
     private float ZInput;
 
     public Transform groundCheck;
     private float radius;
     public LayerMask whatIsGround;
 
     private void Start()
     {
         rb = GetComponent<Rigidbody>();
     }
 
     private void FixedUpdate()
     {
         XInput = Input.GetAxis("Horizontal");
         ZInput = Input.GetAxis("Vertical");
         rb.velocity = new Vector3(XInput * speed, rb.velocity.y, ZInput * speed);
 
         isGrounded = Physics.CheckSphere(groundCheck.position, radius, whatIsGround);
 
         if (Input.GetKeyDown(KeyCode.Space) && isGrounded == true)
         {
             rb.velocity = Vector2.up * jumpForce;
         }
     }
 
 }
Comment
Add comment · Show 2 · 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 igothacked092 · May 14 at 11:25 AM 0
Share

thank you for your response @BKN_Nahar . I am no longer getting any type of errors but still the jump mechanic is still not working. I also do have to note that the project is 3d

avatar image BKN_Nahar igothacked092 · May 14 at 12:12 PM 0
Share

You're welcome.. Hmm, that’s weird, maybe try increasing the groundCheck radius and also don’t forget to add the layerMask to your ground.
It will also make more sense if you change “Vector2.up” to “Vector3.up” where you apply the jump force.
Try using these tips, if they still don’t work, then feel free to let me know again.

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

168 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

Related Questions

Multiple Cars not working 1 Answer

How to find Gameobject with given coordinates 1 Answer

Need help with generating random Multiplier,Need help with generating random multipliers 0 Answers

What do VFXManager scripts usually do? 0 Answers

Possible to use if-statement using the ?-operator with only a single statement? 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