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 grammo106 · Jul 21, 2011 at 10:43 AM · pointcontact

Point of contact with player

I am using the FMOD Event Manager in Unity and need to send it a Vector3 about where I want a sound to play. Using this I want to create a sound from a wall when the player hits it.

I basically want to get the point of contact each time the player hits the wall so that the sound will play from there. I've been through the Unity script reference and so far I can't seem to get ContactPoint to do this. Could anyone suggest a way of getting a script attached to a wall to give me the position of the player's point of contact each time it happens?

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
2

Answer by aldonaletto · Jul 21, 2011 at 11:29 AM

Add this script to the wall and it will produce the sound wallSound at the contact position:

 var wallSound: AudioClip;
 
 function OnCollisionEnter(col:Collision){
 
     if (col.contacts.Length>0){
         AudioSource.PlayClipAtPoint(wallSound, col.contacts[0].point);
     }
 
 }

EDITED: I don't know much about FMOD, thus I can't tell how to pass the point to it, but the basic idea still applies - you can get the collision point from the contacts array in OnCollisionEnter. But if the character is a Character Controller, it will not work - you should use OnControllerCollisionHit and get the point directly from the ControllerCollisionHit structure - but there's a problem: the Character Controller reports collisions with the ground all the time, so you must filter the normals returned to only accept those almost horizontal, like below:

function OnControllerColliderHit(col:ControllerColliderHit){

 if (Mathf.Abs(col.normal.y)<0.2){ // accept only almost horizontal collisions
     if (col.collider.tag == "Wall"){ // and only from objects tagged "Wall"
         var point: Vector3 = col.point;
         // do whatever you want with the collision point
     }
 }

}

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 grammo106 · Jul 22, 2011 at 06:22 PM 0
Share

Aaah, good idea! Thanks mate, worked like a dream! The F$$anonymous$$OD bit is quite simple, for every sound it plays you just send it a Vector and it plays the sound in that location.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How to find the point of contact with the function OnTriggerEnter??? 4 Answers

Using contact point 1 Answer

Problem with contact point 0 Answers

How to send a gameobject to a sepcific position in the 3d environment? 3 Answers

Camera to follow the mouse to move to create the point 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