Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 mradamw · Oct 15, 2014 at 05:28 PM · controllercolliderhit

OnControllerColliderHit troubles with picking up objects.

Hi there,

I'm having some trouble with OnControllerColliderHit and was hoping to get some input on it.

Here's the script I have right now:

     // Pickup ammo
     void OnControllerColliderHit (ControllerColliderHit hit) {
 
         // When we hit a bullet on the ground, tagged with `pickUp_bullet`
         if (hit.collider.gameObject.tag == "pickUp_bullet") {
 
             // We destroy it
             Destroy(hit.gameObject);
 
             // And add it back to our ammo count
             clipSize++;
             countAmmo();
         }
     }

The idea behind this is to pick up bullets on the ground and add them to your ammo count. The problem I'm encountering is that while this works as it should, I've discovered a way to abuse this script to get more bullets than you should. I can only imagine its the way the ChatacterController collider and the object I'm picking up are interacting. Sometimes, if the prefab is on the ground waiting to be picked up, it can be counted twice.

The bullet prefabs have tightly fitting capsule colliders.

Would it make sense to move this into the void Update () {} so that it's checked once a frame?

It's worth noting, that these bullets cannot be marked as triggers, as they are instantiated prefabs fired from a gun.

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 MrSoad · Oct 15, 2014 at 06:58 PM 0
Share

The bullets can be triggers if you want them to be.

0 Replies

· Add your reply
  • Sort: 

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

ControllerColliderHit, two objects, takes wrong one 1 Answer

OnControllerColliderHit, hit.normal direction is unstable 0 Answers

How do i Kill Enemy with Vehicle?? 2 Answers

ControllerColliderHit.moveDirection and ControllerColliderHit.normal 1 Answer

How do I make a cube rigidbody pushable by the default 3rd person character controller without tilting and going left and right? 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