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
1
Question by Disaster · Oct 20, 2010 at 02:46 PM · collisionphysicsraycast

Collision position - Improving on the 'grounded' mechanic

Hi,

At the moment, my character is able to jump whenever he is 'grounded'. I am setting grounded to true whenever the character collides with an object, using OnCollisionStay. The problem with this is that it means that if the collision with with an object above or to the sides, you are able to jump again meaning you can effectively wall jump endlessly.

What I want to do is fix this so that you are only able to jump when you have ground beneath you, so only on collisions below the character. I have two possible methods for doing this:

1) Constantly cast a ray downwards, and only set grounded to true when the ray contacts some floor.

2) Using the OnCollisionStay, check the location of the collision, ensure it was below you and then allow the player to jump again.

I'm unsure of which method is best, and I have no idea if you can check the location of a collision for number 2.

Can anyone 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

2 Replies

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

Answer by lhk · Oct 26, 2010 at 05:18 PM

The Raycast seems good to me. Physics.Raycast() returns true or false depending on wether the ray has hit something or not. So if you set up the ray with correct parameters you should be able to use the return value for your grounded variable. Moreover the additional parameter RaycastHitInfo offers plenty of information about the object that was hit, the GameObject for example. Thus you could add poisoned floor and lava or bouncy surfaces to your game quite easyly.

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
1
Best Answer

Answer by Atnas1010 · Oct 28, 2010 at 04:05 AM

The ray seems like a good idea, except if you want your character to be able to jump when standing more than halfway out on a ledge.

If you want him to be able to do that, I would suggest adding a new collider as trigger under him, slightly smaller than the real collider. You could then use the trigger events to do your game logic.

Oh, and you didn't say anything about whether you are limiting the rays length, but I assume you are, since it wouldn't make much sense otherwise :)

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

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

No one has followed this question yet.

Related Questions

RAYCAST KNOWLEDGE HELP!!! 1 Answer

Raycast length must be equal to the target distance 2 Answers

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

raycasts only working with IsTrigger colliders? 1 Answer

Play Audio-Clip On Ray Casting Collision 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