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 /
  • Help Room /
avatar image
0
Question by Oliver Edge · Jun 16, 2016 at 09:23 AM · colliderscharacter controllercollisionskinematicrigidbody-collision

Collisions won't work(Please check text)

Hi guys,

I know this question has been asked like thousands of times, but after I checked pretty much every other question I still couldn't fix the problem. So I thought I should have write here about this. Now before I start my question please excuse me for my bad english, I'm not native.

So here it is:

In my game I have the standard unity FPS controller with a rigidbody fixed to it(since I want to experience the full body awareness). The basic FPS script comes out with a character controller which is if I'm not mistaken an actual collider(I've just enlarged the radius so part of my body and weapons wouldn't clip through things) so it should work on itself. Point being I have a rolling boulder with a sphere collider attached to it(no trigger) and a rigid body with a greater mass than my player. As they make contact the player should change is animation and fall on the ground, but I've managed to make this happen only a couple of times and I've never changed the actual code.

This is the code:

 function OnCollisionEnter (other : Collision){
     if (other.collider.CompareTag("Hazard")) {
             anim.SetTrigger("Die");
     }
 }
 

Yes the boulder has the "Hazard" tag. "anim" is my reference to the animator component and so far worked for all the other animations.

What usually happens is that the boulder simply raise above the player head and once he passed through it keeps walking till the end of the map. They definitely make contact though. The only idea I had so far was that the character controller works differently from normal colliders but removing it and putting a capsule collider made the FPS controller unusable(not that surprises me, but it would require changing a lot of code not made by me).

Other issue I have with colliders is: I have a weapon spawning only when I press a button(by default both mesh renderer and capsule collider are disabled). When I spawn the weapon the mesh render is enabled but the capsule collider only activates when I press the "Attack" button. When I press the "Attack" button I can see in the inspector the capsule collider becomes enabled for the duration of the attack animation, then it is disabled again. During this period if the capsule collider of the weapon collides with other colliders something should happen. For example I have this wall and I want to play a sound when the weapon hits it. But the code:

 public void OnTriggerEnter(Collider other){
         Debug.Log (other.gameObject.name);
         if (other.gameObject.tag == "Wall") {
             Destroy (other.gameObject);
             PlayWallSound ();
         }
 
     }

Seems not to be working. I know that in order to actually collide both objects must have a collider not set as trigger and at least one of them must have a rigidbody attached. In my case wall has a box collider with trigger off and my weapon has a capsule collider with trigger off and a rigidbody set to use gravity and to be kinematic.

It would have made more sense if I'd put a rigidbody on the wall instead of the weapon(or both of them) but I couldn't avoid the wall from falling on the ground has I attack. So i decided to put it on the weapon. Is kinematic is set to avoid the weapon to fall on the ground once it spawns in the hands of the character.

So to reiterate both problems seems to be related to colliders and I'm pretty sure character controller is causing that problem. Hope I've explained the better I could.

Please if you require any other part of the code feel free to ask. I'll answer the faster I can.

Hope you guys can help me, I'm pretty much stuck here.

Thanks for reading till here and thanks in advance to all who'll spend their time helping a newbie as me.

Cheers :-)

Comment
Add comment · Show 1
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 Oliver Edge · Jul 05, 2016 at 01:46 PM 0
Share

UPDATE: For all those who might come to this topic with the same problem.

I managed to solve it with a not very polite solution, but at least it now works.

I put two colliders: One which guarantees that objects doesn't clip through them(the physical one) and a litte larger one which "is trigger" and which make everything work when objects make contact.

Hope this will help someone.

See ya ;-)

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Oliver Edge · Jun 18, 2016 at 11:21 AM

I think I managed to solve the boulder problem by using the proper function for character controllers "OnControllerColliderHit".

Still no way to manage the other problem though.

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 Oliver Edge · Jun 22, 2016 at 11:11 PM 0
Share

UPDATE: OnControllerColliderHit has the problem in which my character has to move in order to actually calculate the collision(like it is stated in the unity documentation).

I tried to put a normal OnCollisionEnter but as stated in the first post of this topic I still can't make them work.

This means that the wall still doesn't produce any sound when it and that the boulder doesn't kill the character if it stands still.

Hope someone will read and answer though...

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

Jumping with non-rigid character.,Dragged object Enters Ground freely 0 Answers

Triggers Colliding With Triggers Not Working? [Solved] 1 Answer

Colliders for tunnels 0 Answers

Objects falling through plane 1 Answer

Collisions Detection Functions Not Called, Walking Through Walls 2 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