- Home /
Collision Help
Why wont this work? its supposed to see if the type of ground is grass. and if its grass it changes the interger to one. then if its wood, change it to two. i couldnt find out how to get it to detect the tag to see if it was grass, so i just used a string in a seperate script. if you could remake it so it checks the tag that would be great!
var groundType : int;
function OnCollisionEnter(collision : Collision){
if (collision.GetComponent(GroundTypeScript).GroundType == "Grass"){
groundType = 1;
}
else if (collision.GetComponent(GroundTypeScript).GroundType == "Wood"){
groundType = 2;
}
}
Answer by Seth-Bergman · Jul 25, 2012 at 07:14 PM
To check by tag:
var groundType : int;
function OnCollisionEnter(collision : Collision){
if (collision.gameObject.tag == "Grass")
groundType = 1;
else if (collision.gameObject.tag == "Wood"){
groundType = 2;
}
}
this should work if both objects have a collider (or character controller), not set to trigger..
the player probably should also have a rigidbody
for detailed info of what combos will/won't send collision message see this link:
http://docs.unity3d.com/Documentation/Components/class-BoxCollider.html
check out the matrix at the bottom, it should help...
It still wont work when the character controller touches the terrain or the wood floor.
are the objects properly tagged?
try adding a Debug.Log:
function OnCollisionEnter(collision : Collision){
Debug.Log("entered collision");
if (collision.gameObject.tag == "Grass")
also, you probably need to add a rigidbody
again, check the matrix at the link above for specifics
It seems to work now. but the rigidbody makes my first person controller move weird.
you could put the rigidbody on the other objects ins$$anonymous$$d, and set them to kinimatic if you don't want them to be affected by physics (if it's the floor, you probably don't)
Well this is a footstep script. so it would be very complicated to have the floor have a rigidbody.