- Home /
Question by
Arenim · Feb 11, 2014 at 11:17 AM ·
2dcollisioncollision detectionnewbie
Objects don't collide
Hi there!
I've made a sphere which follows user's mouse. Here it's script:
var mycamera: Camera;
mycamera = GameObject.Find("cam").camera;
function Update ()
{
var mpos = Vector3.Normalize(mycamera.ScreenToWorldPoint(Input.mousePosition) - transform.position);
transform.Translate(mpos * ( 5.0 * Time.deltaTime ) );
transform.position.z = 0.0;
}
function OnCollisionEnter(theCollision : Collision)
{
Debug.Log("test");
}
I've also added a collider into it. After all, I've duplicated a sphere, so they're both following mouse.
But they don't collide (I don't see 'test' message in console).
What am I doing wrong?
Comment
Best Answer
Answer by DajBuzi · Feb 11, 2014 at 11:23 AM
Its because youre using transform.Translate to move them. Translate works just like you would change the position in the editor.
Try using rigidbody or charactercontroller to move objects.
Your answer
Follow this Question
Related Questions
Collision detection issue 1 Answer
Child Collides If Its The Parents Collider 0 Answers
Childs Collision Calls Parents OnTriggerEnter2D() 0 Answers
Collision & 2D 2 Answers
isTouching() with multiple colliders 0 Answers