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 TaylorAnderson · Aug 07, 2012 at 07:53 PM · collisioncharacter controllerbox colliderplatforms

Platform collision detection

I want a platform that will destroy itself if the player is moving beyond a certain speed. However, I can't find the collision function that will work for me. I can't do OnTriggerEnter because if I check the 'Is Trigger' on the platform's box colider, the player will just fall through. The player has a Character Controller attached, but I'm finding that OnControllerColliderHit won't work either. Any suggestions?

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

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by ScroodgeM · Aug 07, 2012 at 07:55 PM

AFAIK OnControllerColliderHit method works only on character collisions itself. so you should use OnCollisionEnter on platforms to detect player...

Comment
Add comment · 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
0

Answer by Muuskii · Aug 07, 2012 at 07:59 PM

Note how in OnCollisionEnter you actually have a relative velocity value that you can check. If it's higher than a threshold Destroy the platform and make sure to set the Rigidbody.velocity like so:

 Other.rigidbody.velocity = rigidbody.relativevelocity * scaler;   //He loses a little bit of speed

Edit: Oops, just saw: Character controller (hate those) not rigidbody. Oh well, my suggestion stands.

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 TaylorAnderson · Aug 07, 2012 at 08:03 PM 0
Share

I managed to get it working by adding another game object parented to the platform that isnt rendered and has isTrigger checked, and then i just attach the script to that.

avatar image
0

Answer by Develogamer · Aug 07, 2012 at 08:02 PM

If you want to detect when the player hits a platform then you can use OnCollisionEnter(), which is called the first frame of a collision. You can put a collision parameter on the function to get more info on the actual collision i.e the force on the collision and such. For example, in c#:

 void OnCollisionEnter(Collision collision)
 {
    if(collision.gameObject == platform)
           Destroy(collision.gameObject);
 }

If the player is already on the platform you can use OnCollisionStay which is called every frame that the player is colliding with it. Hope this helps.

Here is the link with the info you can get from the Collider class: http://docs.unity3d.com/Documentation/ScriptReference/Collision.html

Comment
Add comment · 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

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

Not colliding with a box collider? 2 Answers

Collision between Character Controller and Box Collider 2 Answers

Box collider with rigid body yet enemies still pass through each other. 1 Answer

A Character Controller with another shape. 0 Answers

Getting a sword in place while attacking an enemy 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