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 Teyandee · Nov 12, 2015 at 09:32 PM · collision detectionjumping

What is the 3D equivalent of using Physics2D.OverlapArea to check for if a character is grounded?

In this Unity tutorial, http://unity3d.com/learn/tutorials/modules/beginner/2d/2d-controllers at 53 minutes in, they use Physics2D.OverlapCircle to check if the character is touching the ground so that they can enable jumping. Since I have a game of all 3D objects, it isn't working (at least that's my guess why its not working). So I am looking for a 3D alternative to program this same kind of mechanic.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by OncaLupe · Nov 13, 2015 at 01:53 AM

You are right about why Physics2D.OverlapCircle isn't working. Unity has 2 physics engines, one for 2D and one for 3D. The two systems cannot interact with each other.

This is the 3D equivalent you're looking for:

http://docs.unity3d.com/ScriptReference/Physics.OverlapSphere.html

Comment
Add comment · Show 1 · 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 Teyandee · Nov 13, 2015 at 07:35 PM 0
Share

Thank you for not only giving me the right place to look for the solution but also explaining the two engines don't interact! The OverlapSphere worked but I ended up using a microscopic OverlapCapsule for pinpoint results.

avatar image
0

Answer by killer-zog · Nov 12, 2015 at 10:59 PM

have you tried attaching a character controller? this is how to do it in 3D

 using UnityEngine;
 using System.Collections;
 
 public class ExampleClass : MonoBehaviour {
     void Update() {
         CharacterController controller = GetComponent<CharacterController>();
         if (controller.isGrounded)
             print("We are grounded");
         
     }
 }
Comment
Add comment · Show 3 · 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 Teyandee · Nov 12, 2015 at 11:14 PM 0
Share

I'm trying to avoid the character controller because it doesn't simulate the physics I'd like.

avatar image killer-zog Teyandee · Nov 13, 2015 at 04:28 AM 0
Share

well unity also has Physics.OverlapSphere, you can try it. There are some other way to do it though, you can manually check for collision

     void OnCollisionEnter(Collision collision)
     {
 
     }

and then use :

         if (collision.gameObject != null)
         {
             if (collision.collider.shared$$anonymous$$aterial != null && collision.collider.shared$$anonymous$$aterial.name != "Physics material name")
             {
                 isGrounded = true;
             }
         }
 

you can check if it is ground by using not equal operator with the assigned Physics $$anonymous$$aterial. this will make sure that only the collider that has the material assigned will trigger isGrounded to true.

You can also replace that material checking to check of certain Tags or Layers too.

also whenever you tryto use something from 2D counterpart, just remove 2D from behind and unity should have the same behavior for 3D counterpart for most of the time. eg.

 // 2D to 3D
 OnCollisionEnter2D          >          onCollisionEnter
 Physics2D                           >          Physics
 



avatar image killer-zog Teyandee · Nov 13, 2015 at 04:35 AM 0
Share

Also you can use raycasts to check the distance from the ground. Although i found the combination of collider(the code i posted above) and raycast works best. Using Raycast to check the distance from ground and also check if it colliding with ground collider!

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

33 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

Related Questions

Need Help with Jump Coding 0 Answers

Collision not detecting with collider and rigid body 0 Answers

How to check if dragged object collide with other object? 0 Answers

2D colliders doesnt work with Gravity Scale = 0 0 Answers

Objects not being destroyed 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