- Home /
Question by
anurooppv · Dec 05, 2014 at 11:45 AM ·
Ball travelling in wrong path after collision
Attached is my game scene. The ball has a sphere collider & I am checking the collisions between the ball & the obstacles. Sometimes, after collision the ball travels in some random direction. I want the ball to travel forward till the game ends. Sometimes it works fine.
Below is the code:
void OnCollisionEnter(Collision collision)
{
Debug.Log ("collision!!!");*
if (collision.gameObject.name == "BottomObstacle") {
Debug.Log ("bottom");
hits++;
transform.position = new Vector3(transform.position.x, transform.position.y + 0.1f, transform.position.z);
transform.Translate (Time.deltaTime * 2, (float)(double)0, (float)(double)0);
} else if (collision.gameObject.name == "TopObstacle") {
Debug.Log ("top");
hits++;
transform.position = new Vector3(transform.position.x, transform.position.y - 0.1f, transform.position.z);
transform.Translate (Time.deltaTime * 2, (float)(double)0, (float)(double)0);
}
Is there anything I am missing? What could be the possible reason?
Comment