- Home /
Terrain collision and specific collision problems .
Hi All
I am wanting to create a script where if the player runs into the coin then he recieves money and I have the money adding part down but when I add On.Collide then it either collides with the terrain and adds all the coins money or it I make it collide with a specific gameobject then the coins fall through the terrain ? How would I fix this ?
Ps. The terrain has a terrain collider and is no a trigger .
Answer by Rabbit-Stew-dio · Mar 18, 2012 at 01:40 PM
OnCollide is called for all collisions. So simply test that you are actually colliding with your player and you will be fine. Assuming that you tagged your player object as "Player", you can use:
void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.tag == "Player")
{
// collect the coin and get rich
}
}
The only problem is when I tag the player then it falls right through the terrain because I have to had a ridgid body to the coin and gravity for it to work ?
Your answer
Follow this Question
Related Questions
Camera Colliding with Terrain 1 Answer
Detail Mesh doesn't collide. 2 Answers
Collision Help 1 Answer
How can I make a sound deploy after colliding with a certain object (or terrain)? 1 Answer