• 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
Question by rklalbahadur · Jan 22, 2018 at 11:40 PM · collider3dcollidersspherecolliderpickups

3D game: Pickups don't disappear when player touches them.

So I am making a 3D game where the player has to touch a jaguar to make it disappear. The jaguar is a pickup. I am new to Unity, but now I had some experience with the 2D games and I made two 2D levels. This is my first 3D game. The game would be finished by now, if only I could fix the problem. I did follow the Roll-a-Ball 3d tutorial and here is the code they gave me for colliding with a pickup (jaguar in this case). I've used this chunk of code for my 2D levels, but I don't need to share my entire code:

  void OnTriggerEnter(Collider other)
  {
      if(other.gameObject.tag == "Jaguar")
          other.gameObject.SetActive(false);
      
      
  }

In this game, I do not have problems with the colliders at all. I know for sure they are touching each other. I used Sphere colliders in this game for each jaguar and the player itself. I have the "Is Trigger" on in the jaguars, and the "Is Trigger" off on the player (That's how it worked in my 2D games). The jaguars have the "Jaguar" tag. But still, nothing is happening when the player's collider touches the jaguars' colliders. I do have the Sphere Colliders and Rigidbody on all the jaguars and the player

Comment

People who like this

0 Show 0
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

4 Replies

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by KittenSnipes · Jan 23, 2018 at 07:21 PM

@rklalbahadur

I am not sure this will help but maybe try removing the Jaguars from the empty game object and then test them to see if it works

For those wondering here is the working script:

Working Script

Comment
akaCarbone

People who like this

1 Show 17 · 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 rklalbahadur · Jan 23, 2018 at 11:08 PM 0
Share

You have a point there, but it doesn't work. I took it out of the empty object. @KittenSnipes

avatar image KittenSnipes rklalbahadur · Jan 23, 2018 at 11:10 PM 0
Share

I am willing to help in any way I can mate.

avatar image KittenSnipes rklalbahadur · Jan 23, 2018 at 11:12 PM 0
Share

@rklalbahadur

Whatever you need mate just ask. I know the struggle of getting your project to work.

avatar image rklalbahadur KittenSnipes · Jan 23, 2018 at 11:15 PM 0
Share

Someone did ask me to send it to them, which I don't mind sending to you if you want.

Show more comments
avatar image KittenSnipes · Jan 23, 2018 at 11:50 PM 0
Share

Here is the script that works for me and I used your level 3. Here is the download link and make sure to drag this script on to your player on level 3.

Download Link

avatar image rklalbahadur KittenSnipes · Jan 24, 2018 at 12:00 AM 0
Share

@KittenSnipes Thank you this actually worked!

avatar image KittenSnipes rklalbahadur · Jan 24, 2018 at 12:01 AM 0
Share

No problem :D

Show more comments
avatar image

Answer by NoobGaming · Jan 23, 2018 at 12:29 AM

May seem dumb but it's gotten me before. Make sure your tag is spelled the same way in code as it is in the inspector. It is case sensitive. Let me know if that helped you out.

Comment

People who like this

0 Show 7 · 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 NoobGaming · Jan 23, 2018 at 12:39 AM 0
Share

Plus unless your Jaguars are using physics there's no need for them to have RigidBodies on them. Just need one for the player. The Jaguars are not required to have a RigidBody for the Trigger collision.

avatar image rklalbahadur · Jan 23, 2018 at 12:49 AM 0
Share

@NoobGaming The tags match what the code said. The cases are fine. I did take of the RigidBody for the jaguars. Still no success.

avatar image NoobGaming rklalbahadur · Jan 23, 2018 at 12:57 AM 0
Share

Weird. Try this and make sure your getting a collision:

 void OnTriggerEnter(Collider other)
   {
       if(other.gameObject.tag == "Jaguar"){
           other.gameObject.SetActive(false);
           Debug.Log(other.gameObject.tag);
       }
   }

And see what prints in the console.

avatar image NoobGaming NoobGaming · Jan 23, 2018 at 12:59 AM 0
Share

Also is your Jaguar a child object of anything or just its self?

Show more comments
avatar image

Answer by Tryptex · Jan 23, 2018 at 12:43 AM

Make sure that both your players colliders and your pickups colliders are set to be triggers in the editor.

Comment

People who like this

0 Show 5 · 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 rklalbahadur · Jan 23, 2018 at 01:11 AM 0
Share

No, that didn't work. But like I said, for my 2D game, I had the trigger off on the player and the triggers on for the jaguars (pickups).

avatar image Tryptex rklalbahadur · Jan 23, 2018 at 01:13 AM 0
Share

Ok, this sounds dumb but have you tried rebooting your computer?

avatar image rklalbahadur Tryptex · Jan 23, 2018 at 01:19 AM 0
Share

yes all of that

Show more comments
avatar image

Answer by GliconCraft · Jan 23, 2018 at 01:30 AM

In the Roll a Ball beginner unity tutorial, the narrator goes over this during the part where he's setting up the collectibles, maybe you can watch that part and try to make sure everything is set up completely right?

https://unity3d.com/learn/tutorials/projects/roll-ball-tutorial/collecting-pick-objects?playlist=17141

Here's the link for that video in the tutorial.

Comment

People who like this

0 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 Tryptex · Jan 23, 2018 at 05:30 PM 0
Share

OK, Unfortunately I still have not found out why it is not working, NoobGaming is right though type:

 void OnTriggerEnter(Collider other)
    {
        if(other.gameObject.tag == "Jaguar"){
            other.gameObject.SetActive(false);
            Debug.Log(other.gameObject.tag);
        }
    }

If you have anything coming up in your console saying the name of the object that was touched, that will tell us that the ball is sensing the Jaguar correctly and that there is something wrong with how the Jaguar is being disabled. If you don't see anything there when the ball touches a Jaguar, that means that there is something wrong with how the ball is sensing the Jaguar.

avatar image rklalbahadur · Jan 23, 2018 at 11:09 PM 0
Share

@fierce_t Still followed through and still no success.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

97 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 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 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 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 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 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 avatar image

Related Questions

how to Stop Enemys from clipping into eachother? 0 Answers

3D Colliders isue 1 Answer

My 3D collider is not detecting colissions. 1 Answer

Can I make a hole in a mesh collider? 2 Answers

Tilt Brush clone with Kinect, HMZ-T1 and Unity 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