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 superluigi · Aug 09, 2013 at 12:00 AM · ontriggerenter

My character controller wont detect collision when crouching.

Hi so I have arrows as triggers flying at my character. If hes standing the onTriggerEnter function works just fine, he loses one health and is knocked back. However, if I crouch nothing I dont get hit, for some reason the OnTriggerEnter function isn't being called. I turn off the mesh renderer and look at my collider on the scene view and even though the arrows are clearly entering the player the onTriggerEnter function doesn't detect it.

 function Crouch()
 {
     if (controller.isGrounded && Input.GetKey("s"))
     {
         crouching = true;
         controller.height = crouchHeight;
         controller.center.y = crouchCenterY;
     }
     else if (Input.GetKeyUp("s"))
     {
         gravity = 0;
         crouching = false;
         controller.height = standHeight;
         controller.center.y = standCenterY;
         gravity = normalGravity;
     }    
 }
 
 function OnTriggerEnter (other : Collider)
 {
     if (!invincible)
     {
            if(other.gameObject.tag == "enemy")
         {
             print("gotHit");
             hit = true;
                 health -= 1;
                 invincible = true;
             yield WaitForSeconds (2.5);
             invincible = false;
         }
     }
 }
Comment
Add comment · Show 7
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 cdrandin · Aug 09, 2013 at 12:22 AM 0
Share

$$anonymous$$ake sure your character controller collision box is going where it needs to go. Check the green outline in the inspector and see where the collider is going.

avatar image superluigi · Aug 09, 2013 at 01:30 AM 0
Share

I turn of the mesh renderer for the capsule and in the scene view the capsule collider is what I'm looking at. I can't figure out what going on.

avatar image cdrandin · Aug 09, 2013 at 01:45 AM 0
Share

adjust the levels of height. With just code I don't know what is going on at all. I don't even know what your problem is. You are just simply saying. It doesn't work.

avatar image superluigi · Aug 09, 2013 at 02:15 AM 0
Share

so I changed controller.center.y to transform.position.y and now its working. However, now I have a new problem. If I press the crouch button crazy fast my character falls through the floor.

avatar image cdrandin · Aug 09, 2013 at 02:31 AM 0
Share

It is tricky. If the collider is already colliding with some some object at that start it goes crazy.

Ex. You put a collider on an object so it wont fall through the plane. Put the collider just .001 units into the plane and you immediately fall through. So, this just requires careful tinkering.

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by MrRandomFella · Apr 08, 2014 at 09:32 AM

I'm not too sure about this, but anyway. I have tried to use a similar crouching script to yours and I've noticed that collisions with the floor seem to disappear whenever I crouch too low. So remember to set that at a reasonable height. Secondly, have you tried using the "DontGoThroughThings" script on the wiki? I think your controller may be failing to detect the fast moving arrows whenever you crouch. This is just a thought of mine, I don't know if this will fix your problem. Script

  • tried :/

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 superluigi · Apr 17, 2014 at 07:17 AM 0
Share

thanks for the answer. This is an old question, but currently I am using hitboxes ins$$anonymous$$d. When I hit down to crouch my standing hitbox will deactivate and the crouching one will activate. Of course this is for an entirely different project but I suppose it would work for this one too. I'll have to go back and try it.

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

16 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

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

OnTriggerEnter - destroy (this.gameobject) if it collides with anything 2 Answers

Collider doesn't transfer to function 1 Answer

Null reference that isn't null 2 Answers

Error accessing var from other scripts within project via GetComponent 1 Answer


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