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 Myhijim · Jul 01, 2012 at 11:05 AM · audiooncollisionentercollisionsfirst person controller

OnCollisionEnter Issues

Well im going to be straightfoward here, this is my code

 var collisionObject : Transform;
 
 
 function OnCollisionEnter(collision : Collision)                    //This function tests the collision and plays a sound
 {
 if (!audio.isPlaying && collision.gameObject == collisionObject)
 {
 audio.Play();
 print("Play");
 }
 }


The "collisionObject" is the FPC and yes it has a rigidbody, the object the script is assigned to is a collision box with a Audio thing attached

I have no idea why it wont play....

Thanks Myhijim

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 Owen-Reynolds · Jul 01, 2012 at 03:24 PM

So, this script is on a collider w/rigidbody and should be hit by the player, which uses a characterController?

CharControllers don't trigger OnCollisionEnter when they hit things. They don't use physics to move, which is where collisions happen. To test, add Debug.Log("hit by" + collision.transform.name); as the 1st line. You can verify it isn't the math -- there's just no collision at all.

Instead need to use OnCharContHit. There are a bunch of threads here on that, and hacks that don't really work (like adding a dummy isKinematic collider in front, which tends to just block the player's movement.)

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 Myhijim · Jul 02, 2012 at 03:03 AM 0
Share

Thanks, but what if i dont want it to stop the player, i phrased the question badly, i just want a collision box that sets off a noise as the player goes through it

avatar image Owen-Reynolds · Jul 02, 2012 at 05:34 AM 0
Share

A zone that simply detects your presence is a triggerBox. Check isTrigger on the collider (it will no longer block anyone) and use the OnTriggerEnter event. Also see the docs. Those do detect charControllers just fine.

avatar image Myhijim · Jul 05, 2012 at 11:51 AM 0
Share

Exactly what i needed! Thank you

avatar image
0

Answer by whydoidoit · Jul 01, 2012 at 11:07 AM

collisionObject is a transform and collision.gameObject is a game object so they will never be equal! Perhaps define collisionObject as GameObject or check the transform of collision.gameObject.

Comment
Add comment · Show 2 · 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 Myhijim · Jul 01, 2012 at 12:03 PM 0
Share

Nope that didnt work :( Thanks anyway

avatar image whydoidoit · Jul 01, 2012 at 12:10 PM 0
Share

I suggest you Debug.Log both objects with .ToString(). They clearly aren't matching.

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

7 People are following this question.

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

Related Questions

Any Idea why my Explosion sound is NOT playing ? 1 Answer

Can not get OnTriggerEnter and OnCollisionEnter to work!? 1 Answer

get collision info from main script? 1 Answer

First Person Controller Colliding Fail 0 Answers

Testing first person controller (mobile) and can't get the collisions to work 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