Jump to content
This site uses cookies! Learn More

This site uses cookies!

armedunity.com uses cookies to improve user experience.

By continuing to use this site, you agree to allow us to store cookies on your computer.

  • 0
Sign in to follow this  

Question

Hi!
I want to detect if the player is grounded, there's something above his head and if it's colliding with walls from sides in one script.
I have a basic movement script, what detects if the player is standing, but I want it to detect if there's something above his head, so when im crouching, i won't get into objects. How can I get the two collison info seperated? Here's the code that I'm using:

Please login or register to see this code.

Also how can I simply describe the two sides in one for wall-jumping (so (Please login or register to see this link. .Please login or register to see this link. (contact.Please login or register to see this link. ,/ Please login or register to see this link. .left AND right/)?

Any help would be appreciated.)

Share this post


Link to post
Share on other sites

7 answers to this question

Recommended Posts

  • 0

Hi, you could create another collider and place (child it) for the head, make it a bit bigger than head itself. If that collider is triggering then something is on/around your head.

Or you could shoot a raycast up from your head position, if returned hit.point distance is smaller than some value then that gameobject is near/on your head.

Share this post


Link to post
Share on other sites

  • 0

Ok, got the grounded and the crouching part, but if I want to detect collison's from the sides, do I have to make more objects?

Share this post


Link to post
Share on other sites
  • 0

Depends on the walls and game type, if its temple run style, where walls are pretty much at constant distance from centered player, you could do it by simply checking someCenterPosition + player.transform.position.x, if its greater, less or mathf.approximately equal than lets say -5 or 5, then he is colliding.

Share this post


Link to post
Share on other sites
  • 0

No, I'm making an FPS game, so it wouldn't work. Anyways, thanks for your help.

Share this post


Link to post
Share on other sites
  • 0

I just call Physics.OverlapSphere with the radius of the char controller and a certain offset when uncrouching (press control when crouched). There wouldn't be any reason to check when crouching and its only called once in a while, so performance isn't impacted too much this way. Then use a layer mask to avoid detecting the character controller, and then finally check the length of the colliders array returned by this function. Raycast isn't totally ideal in this situation because it only checks one point while overlap sphere checks an area. And not a fan of using a collider since it would come with a great performance cost when you don't add a rigidbody (that isn't kinematic), otherwise it would count as a static collider, which wouldn't be great when being moved (which would then be called dynamic).

May sound kinda complicated but this is what programming is all about. If you need help on me writing an example, then you're more than welcome.

Share this post


Link to post
Share on other sites
  • 0

And how can I get the Collision for the wall jumping (so I can get the angles)? Is it the same with OnCollisionStay?

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...