- Home /
Im having a Problem with Basic Collision.
Hello! Im trying to make an basic controller. Im using 2D objects in the 3D plane. The issue that I have been having is that I cant get my objects to collide with a basic Box Collider. I have tried everything from using OnTriggerEnter/OnTriggerStay/OnCollisionEnter/....etc but have had no success. However whenever I use CharacterMotor the objects collide and stop.
What I need is a script that when the object hits a box collider it stops and doesnt keep going.
The Script I have been using for Movement
var speed = 5;
var player : Transform;
function Update ()
{
if (Input.GetKey(KeyCode.W)) {
var PositiveForward : float = Time.deltaTime * 10;
transform.Translate(0 , 0, PositiveForward);
transform.eulerAngles.x = 0;
transform.eulerAngles.y = 0;
transform.eulerAngles.z = 0;
}
if (Input.GetKey(KeyCode.D)) {
var PositiveZ : float = Time.deltaTime * 10;
transform.Translate(0 , 0, PositiveZ);
transform.eulerAngles.x = 0;
transform.eulerAngles.y = 90;
transform.eulerAngles.z = 0;
}
if (Input.GetKey(KeyCode.S)){
var Backward : float = Time.deltaTime * 10;
transform.Translate(0 ,0 , Backward);
transform.eulerAngles.x = 0;
transform.eulerAngles.y = -180;
transform.eulerAngles.z = 0;
}
if (Input.GetKey(KeyCode.A)){
var Left : float = Time.deltaTime * 10;
transform.Translate(0 , 0, Left );
transform.eulerAngles.y = -90;
}
}
Im honestly lost im not the best when it comes to coding.
Answer by zeeshandar · Sep 18, 2014 at 02:50 PM
if you are using box collider 2D you should try OnCollisionEnter2D(Collider2D collider) or OnTriggerEnter2D(Collider2D collider) and put debu.log("") in it to check which one is firing and also make sure your direction is not along z-axis..
Im getting collision with the 3D collider. Im using charactercontroller on my player. I used Debug.Log "Hit" and it registers the collision but it just doesnt stop the object.