Sorry if this seems to be a newbie question. However i seems to have problems detecting collision between my player and the gameObject i want to detect. Am i writing it wrong somehow?
One thing to note:
When using onTriggerEnter (this may also apply to collisions) the documentation says that both objects need either a collider or a rigidbody.
In my experience, this is not correct.
This is only true if BOTH Objects are moving.
If one of the objects is standing perfectly 100% still, then the other object will need to have a rigidbody as well.
Try using THIS Unity3D collision method. It should make life a bit easier:
It's a simple check for looking if the collision box of your moving charactercontroller has come into contact with something above below etc. Little else is needed for simple collision detection
Thanks again for the suggestion. However i tried both ways. and it doesnt work also. );
This the whole code for this class. maybe its more informative. =/
class Collisions extends StageWaypoint
{
public var targets : GameObject;
public var targetz : GameObject;
private var thisNum : int;
private var getNos : int;
function Awake()
{
}
function Start()
{
//Debug.Log(targets);
//Debug.Log(targetz);
//Debug.Log("hellosssss");
}
function Update()
{
targets = GameObject.Find("CarrotType1(Clone)");
targetz = GameObject.Find("CarrotType2(Clone)");
getNos = thisNum;
//Debug.Log(getNos + " this is rec");
//Debug.Log(targets);
}
function OnControllerColliderHit(collision : ControllerColliderHit)
{
Debug.Log(" i got u");
if(collision.collider.name == "CarrotType2(Clone)" && getNos == 1)
{
Debug.Log("hello");
Destroy(targets);
}
if(collision.collider.name == "CarrotType2(Clone)" && getNos == 2)
{
Debug.Log("hello");
Destroy(targetz);
}
}
function recNum(no : int)
{
thisNum = no;
}