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 inglipX · Jan 01, 2014 at 10:26 PM · collisioncolliderfootsteps

OnCollisionEnter question....

I am creating a footsteps script with my capsule collider-based player: I am having an issue with collision detection.... If i am on a surface below me and i collide with a new surface in front of me (such as a wall), the collision detection chooses the wall (concrete) sound to play, instead of the ground that i am standing on. Is there a way to make sure that the collision contact is only hitting the bottom of my capsule collider? Thanks

Comment
Add comment · Show 5
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 iwaldrop · Jan 01, 2014 at 10:47 PM 0
Share

The angry bots project has an example in it. Think they might have used a raycast downward.

avatar image inglipX · Jan 01, 2014 at 11:22 PM 0
Share

how would i use a raycast alongside collision detection? If the collided gameobject is equal to the object that the raycast downward detected, then that object is the surface sound we should play?

avatar image iwaldrop · Jan 01, 2014 at 11:37 PM 0
Share

You wouldn't need to do both. The raycast downward is more accurate. I suggested you see how they do it in the angry bots project, however, because I don't remember all the specifics of their implementation. Again, it's worth a look.

avatar image inglipX · Jan 02, 2014 at 12:18 AM 0
Share

ok thanks, and wouldn't all of those constant raycasts be quite performance expensive?

avatar image iwaldrop · Jan 02, 2014 at 12:44 AM 0
Share

No. A raycast is relatively cheap. Try it yourself by casting a ray 1000 times each frame if you wish. Generating the HitInfo is a bit costly, but not as much as generating collision info. Finally, you should only need to cast periodically, to check which sound to play, so it's not going to be happening every frame, right?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by greatwhiteshark17283 · Jan 01, 2014 at 10:33 PM

What you could do is add a collider under the capsule player and make it a child of the player. You could also add a script to the player which detects the tag of the object it's colliding with.

 var objectTag : String;
 
 function OnCollisionEnter(col : Collider){
           if(col.tag == objectTag){
                     //add the sound part here
           }
 }
Comment
Add comment · Show 6 · 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 inglipX · Jan 01, 2014 at 10:35 PM 0
Share

the issue with this is, if the collider under the capsule player is touching the capsule player then it causes collider issues, as one collider is inside of rigidbody; we get physics issues.

avatar image iwaldrop · Jan 01, 2014 at 10:45 PM 0
Share

You'd need to make it a trigger anyway.

avatar image inglipX · Jan 01, 2014 at 10:51 PM 0
Share

i need to use oncollsionenter so i can access contact data

avatar image iwaldrop · Jan 01, 2014 at 10:52 PM 0
Share

You'd use OnTriggerEnter ins$$anonymous$$d.

avatar image inglipX · Jan 01, 2014 at 10:57 PM 0
Share

OnTriggerEnter does not handle collision information, just detects if there was a collision. So i cannot find the point of collision unless i use OnCollisionEnter

Show more comments

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

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

Related Questions

Trouble with Physics.IgnoreCollision 0 Answers

Unwanted jittery behavior 2 Answers

Colliders in a wall jut out 0 Answers

Trouble with OnCollisionEnter and Exit 1 Answer

Giant colliders restricted to a set size? 0 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