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 /
avatar image
0
Question by TheTinkerer · Feb 08, 2016 at 10:38 AM · c#collision detectionjumpingplayer movement

Jump Normal to Collider Surface

Hi All,

I'm working on my player controller and have everything really smooth and robust except the jumping feature. In an effort to reflect real world physics as much as possible, I'm trying to make sure the player model is able to "jump" in a direction normal to whatever surface they are colliding with. I'm thinking similar to the way Titanfall allows the player to wall-run and jump. However, this poses a couple of problems.

There doesn't seem to be a way to determine if a collider is colliding with anything on demand. This would be useful because all that would be required to implement a jump feature would be to grab the player collider, run a test to see if it has any points of contact and if so, where on the player collider those points of contact are. Once those points of contact are determined, use the vectors to those points from the center of the collider and create a vector that is the sum of those vectors. This vector would dictate the direction that is normal to all points of collision. Then jump in that direction.

I've tried looking up CapsuleCollider methods, raycast methods, OnCollision methods, but I feel like I'm missing how to utilize these to get the functionality I'm desiring. I'm sure using OnCollisionStay would work but that sounds like computational overkill as I'm really only interested in changes in collision state, i.e. when a player stops contacting a collider, check to see if the player has any points of collision; if no, then the player is airborne and can't jump.

My question then is: is there a good way to perform on-demand collision point checking in all directions of a collider?

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
1

Answer by Lashes · Oct 14, 2021 at 04:06 PM

Hi - I'm not sure if this would would be a method to use in your specific case, given that you want to check all directions of the collider, but for what it's worth, I used a raycast instead of collision detection to determine if my player could jump, because I realized there may be floating point errors using just strict collision detection. So, for what it's worth, this is what I've come up with (see script below):


(Also, I'm very new to programming -- about a week in now -- so forgive me if this is way off from what you're looking for)

(Also also, I realize this question is 5 years old now, but maybe others have a similar question still...?)


The two relevant functions within my larger 'PlayerController' script look like this:

 // to see if player can jump, check for a raycast down, using origin, direction, and max distance (obj center to floor distance):
 private void Update()
 {
     canJump = Physics.Raycast(playerCenterTransform.position, -transform.up, raycastLength);
 }
 
 // to determine public raycastLength above, visualize by drawing a line (gizmo) when object is selected in the scene (before runtime):
 private void OnDrawGizmosSelected()
 {
     Gizmos.DrawLine(playerCenterTransform.position, playerCenterTransform.position - transform.up * raycastLength);
 }


Anyway, this works for me, and I hope it works for others. And if anyone has any suggestions on improvements, please let me know!

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

How do I jump? 0 Answers

Not detecting collision? 1 Answer

How do i stop infinite Jumping in the air 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