Hi NiceXD,
Welcome to our community! ![:slight_smile: :slight_smile:](https://community.gamedev.tv/images/emoji/twitter/slight_smile.png?v=9)
Thanks for sharing screenshots of what you did and have in the Unity Editor. That’s helpful.
Please take a look at this:
![image](https://community.gamedev.tv/uploads/db2322/original/4X/d/f/1/df13037142b7e5e5a402b4531326d7bb0afcc787.png)
In the Inspector, we can see the ‘package’ game object. This game object has got the ‘Package’ tag assigned. (Notice the word ‘this’ in this sentence because it is important. ;))
We can also see the Delivery component in the Inspector. If you log tag
into your console, you’ll see ‘package’ in yoru console. tag
is short for this.tag
. (That’s why I emphasised ‘this’.)
Does that make sense so far?
Since ‘this’ is the package, the other
game object is very likely not a package because, otherwise, packages would collide with packages. If the other
game object is the Player, other.tag == 'Package'
would be true only if the Player has got the ‘Package’ tag assigned.
Question: Does it make sense to assign the ‘Package’ tag to the Player?
Answer: No, it doesn’t. The Player is a car, so the ‘Player’ or ‘Car’ tag makes more sense.
You solved the problem by checking if the other
game object does not have the ‘Package’ tag assigned. If the player is the only moving collider, the solution is fine.
However, what happens if there are other moving colliders which might collide with the package?
As you probably noticed, I avoided to tell you the problem and solution directly. The reason for that is: There are often multiple ways to make things work. If you apply simple logic, you can modify the code to solve problems your way. That’s fine. If you want to follow Rick’s logic, you probably spotted the actual problem after reading my hints. If not, please let me know. ![:slight_smile: :slight_smile:](https://community.gamedev.tv/images/emoji/twitter/slight_smile.png?v=9)
Here is another hint if you need one:
Is your package able to drive? If not, what’s the purpose of line 9 in the Delivery class?
See also: