• 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 RharryR · Oct 28, 2015 at 12:52 PM · 2d2d-platformerrigidbody2d2d physics

Best ground 2D ground check strategy? How to detect if a object is touching the top of a layer?

Heya.

Im currently making a basic 2D platformer. Up until i have been using the Collider2D IsTouchingLayer function but just realised that i can get away with infinite jumps while touching the bottom of platforms. How would i detect if the player is just touching the TOP of the ground? Thanks in advance.

Comment
Add comment · Show 2
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 RharryR · Oct 29, 2015 at 12:45 AM 0
Share

Anyone? Bump.

avatar image centaurianmudpig · Oct 29, 2015 at 11:16 AM 0
Share

Does IsTouchingLayer() detect if you are touching the top of the ground?

Collider2D.IsTouchingLayers uses Layer $$anonymous$$asks, so perhaps you need to setup a layer to identify the top of the ground, then pass the required parameter when doing the check. http://docs.unity3d.com/ScriptReference/Collider2D.IsTouchingLayers.html

Otherwise, post relevant code (also perhaps some screen grabs on how the scene is set up?) to help others help you.

1 Reply

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

Answer by Socapex · Oct 29, 2015 at 11:34 AM

You can check if it is under you, but you will need OnCollissionX or OnTriggerX methods. For example (non tested, but should work).

 if (coll.gameObject.transform.position.y <= transform.position.y)
     // Object colliding with is under you

In reality, you'll want to check with (coll.gameObject.transform.position.y + coll.gameObject.renderer.bounds.extents.y) and (transform.position.y - renderer.bounds.extents.y). This will give you the exact "bottom" of your character and "top" of platform. Hope this helps.

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 RharryR · Oct 30, 2015 at 12:48 AM 0
Share

Thanks! Finally have some good collision :D

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How can I slow the movement of a single rigidbody2D? 2 Answers

2D player slower on ground than in air 1 Answer

How Do I make my character move? 0 Answers

How to move rigidbodies with 2D Character controller (No rigidbody) 1 Answer

Walking around 2D planets? 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