- Home /
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
Answer by KittenSnipes · Jan 23, 2018 at 07:21 PM
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:
You have a point there, but it doesn't work. I took it out of the empty object. @$$anonymous$$ittenSnipes
I am willing to help in any way I can mate.
Whatever you need mate just ask. I know the struggle of getting your project to work.
Someone did ask me to send it to them, which I don't $$anonymous$$d sending to you if you want.
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.
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.
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.
@NoobGa$$anonymous$$g The tags match what the code said. The cases are fine. I did take of the RigidBody for the jaguars. Still no success.
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.
Also is your Jaguar a child object of anything or just its self?
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.
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).
Ok, this sounds dumb but have you tried rebooting your computer?
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?
Here's the link for that video in the tutorial.
O$$anonymous$$, Unfortunately I still have not found out why it is not working, NoobGa$$anonymous$$g 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 co$$anonymous$$g 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.
@fierce_t Still followed through and still no success.
Your answer
Follow this Question
Related Questions
My 3D collider is not detecting colissions. 1 Answer
Can I make a hole in a mesh collider? 2 Answers
how to Stop Enemys from clipping into eachother? 0 Answers
3D Colliders isue 1 Answer