Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Stopfi · Nov 03, 2014 at 04:31 PM · collision2d gamegrounded

Find out that player is not grounded

How can i find out that my player is actually not grounded? Is there any contrary of OnCollisonEnter?

Thanks for the answers.

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 Stopfi · Nov 03, 2014 at 04:28 PM 0
Share

$$anonymous$$y Character has a Rigidbody2D and I use Rigidbody2D.velocity for movement. The ground is made of BoxCollider2D that may have different rotations. Jumping is not possible.

$$anonymous$$y problem is, that my Player moves away from the platforms when it goes downwards. The player should always be grounded to the lines.

Her is a screenshot of my scene: http://www.directupload.net/file/d/3795/v5jmhlt2_png.htm

avatar image james_170482 · Nov 03, 2014 at 05:23 PM 0
Share

you could raycast down from the players feet and if it hits an object tagged ground for example get the hit point and do something with that? not sure but it could be a good starting point.

2 Replies

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

Answer by fafase · Nov 03, 2014 at 06:39 PM

Since you use 2D you could go for:

 [SerializeField] private Layer ground;
 [SerializeField] private Transform groundCheckPoint;
 
 bool IsGrounded()
 {
     Collider2D col = Physics2D.OverlapCircle(groundCheckPoint.position, 0.1f, ground);
     return (col != null);
 }

The ground check point should be somewhere to the feet.

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
avatar image
0

Answer by b1gry4n · Nov 03, 2014 at 05:53 PM

If you are using a character controller you can use isGrounded

http://docs.unity3d.com/ScriptReference/CharacterController-isGrounded.html

If you are not using a character controller you will have to create your own check as james_170482 pointed out.

"you could raycast down from the players feet..."(I suggest you ray cast from a point above the players feet so that you know for sure it will hit then subtract the height you cast the ray from. Compare the distance to a "maxheightbeforefalling" variable) "...and if it hits an object tagged ground for example get the hit point... "

The great thing about the raycast option is you have the ability to use layermasks with it. Maybe you have certain objects the player can fall through or certain objects you wish to ignore while checking "grounded"

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 b1gry4n · Nov 03, 2014 at 06:41 PM 0
Share

I did not see you were using 2d until now. The methods above (as far as I know, I havent worked with 2d) work with 3d

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

2D:I have a movementController script on my character but it doesn't move forward 0 Answers

Only able to jump when grounded.,Only doing something if something is true 1 Answer

Collider detection in 2D 1 Answer

Unity 2D Collider Safe Sizes 0 Answers

2D collision not registering 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