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 Harry64 · Feb 04, 2013 at 11:21 PM · colliderhitrigidbody-collisioncapsule

CapsuleCollider : How to get the info which part is hit?

I have build a leaning function for my FPS character. to prevent him to look through walls I added 2 CapsuleCollider with rigidbodys around the camera. the outer Capsule stops the leaning so the camera cannot go farther on. the inner Capsule should move the camera a bit back to the center if I walk into a wall.

so now my problem is if I push the "lean right" button and it detects a wall it will stop move. thats good. but when I let the button go and push at the same time the "lean left" button it will still stop moving the camera because I only have this one Collider... same for the inner collider. I cannot determine if I hit a wall on the right side or on the left side...

as I wrote these lines I found a solution that could work but I still want to know if there is a simple line of code that I could add to my Colliders to determine which hemisphere is hit.

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

Answer by Adam-Buckner · Feb 05, 2013 at 04:27 PM

If you are new to scripting and new to the Unity engine, you may wish to look at Raycasting.

http://docs.unity3d.com/Documentation/ScriptReference/Physics.Raycast.html

And instead of using colliders, simply check with a ray (2, if you want to check left and right) for objects to each side.

With the information from the Raycast Hit:

http://docs.unity3d.com/Documentation/ScriptReference/RaycastHit.html

... you will be able to find more details about what and where you've hit an object.

You can then apply your logic based on knowing where that object is.

Comment
Add comment · Show 3 · 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 Harry64 · Feb 05, 2013 at 07:15 PM 0
Share

the problem with a raycasti is that its just a thin line... and my character is leaning to the side and a little down. if it would just check the souroundings like that it would may glitch out on stuff that is standing around or when I am walking while leaning then I would end up with the camera in doors or something. and I would need then 4 raycasts 2 on each side. 1 to check if is there a wall and 1 to check if I am in a wall to move the camera back and then it would not work. I will maybe only use raycast for footstep sound. so the only way would be colliders with rigidbodys.

avatar image Adam-Buckner ♦♦ · Feb 07, 2013 at 09:04 PM 0
Share

You could also look at sphere and capsule cast...

http://docs.unity3d.com/Documentation/ScriptReference/Physics.SphereCast.html http://docs.unity3d.com/Documentation/ScriptReference/Physics.CapsuleCast.html

Here is an explanation on how this could be used: http://www.theantranch.com/Unity/Entries/2011/3/29_Understanding_Spherecasts_in_Unity.html

This way you could cast a volume rather than a ray.

avatar image Harry64 · Feb 17, 2013 at 12:56 AM 0
Share

O$$anonymous$$G I did not know that this is possible! I have already solved the problem with coding http://youtu.be/kPx2evc5RO8?t=4m43s but I think I should replace my uncrouch collider with this because if I really try I can still stand up in walls. how much does this SphereCast affect the FPS? or is it like a Raycast?

avatar image
1

Answer by Adam-Buckner · Feb 04, 2013 at 11:22 PM

You may want to look at:

http://docs.unity3d.com/Documentation/ScriptReference/Collision-contacts.html

If you look at the collision class, you should be able to get the contact points. I am assuming that if you compare the contact point to the center point of the object, you will be able to determine which direction it is in.

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 Harry64 · Feb 04, 2013 at 11:46 PM 0
Share

I should say I am very new to coding.... so I am cunfused... btw I found out that one side of the capsule collider reacts faster to collisions than the other side... when I am leaning to the right it stops the camera to late and the wall hit the inner capsule so it wanders back a little. when I lean to the left it stops also very late but not too late... why is that so?

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

10 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Spawning blood splatter at the point the bullet hit a collider? 1 Answer

Capsule Collider as a motorcycle simulator? 1 Answer

finding vertices by distance to hit point 1 Answer

AddTorque no longer working when collider is added 2 Answers

hit something with collider 3 Answers


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