x


this script is to reset the ball to its initial position after every kick in foorball game..

The problem with this script is that the 'OnCollisionEnter' function is not being called when the ball collide with the collider..can any one help me to find whats the wrong in this script..?? using UnityEngine; using System.Collections;

public class BallSpawnTest : MonoBehaviour 
{

private Vector3 initialPos; 

 private Quaternion originalRotation;


 // Called when the game starts
 void Start()
 {
 // Remeber the ball's initial position. Later we will use it to restore the ball after every kick
 initialPos = transform.position;
 originalRotation = transform.rotation;

 }

 void Update ()
 {
 Debug.Log("update function called");
// Reset();
 }

 void OnCollisionEnter(Collider collide) {
 if(collide.gameObject.name=="Sphere")
 {       
            Debug.Log("collied");
     Reset();
    }

}
 private IEnumerator RestartBall()
    {


    yield return new WaitForSeconds(5);  

               Debug.Log("in restart bal function");

    transform.position = initialPos;

    transform.rotation = originalRotation;

    }

public void Reset()
 {
 StartCoroutine(RestartBall());

 rigidbody.velocity = Vector3.zero;
 rigidbody.angularVelocity = Vector3.zero;

 Debug.Log("function called");
      }

}
more ▼

asked Jul 03 '12 at 12:55 PM

Hims gravatar image

Hims
50 3 11 17

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Check if the both objects, a ball and a collider, have rigidbodies.

more ▼

answered Jul 03 '12 at 01:48 PM

Wolin gravatar image

Wolin
61 2 3

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3316
x2482
x168
x167

asked: Jul 03 '12 at 12:55 PM

Seen: 309 times

Last Updated: Jul 03 '12 at 01:48 PM