Reputation: 20565
I have the following script:
using UnityEngine;
using System.Collections;
public class BallScript : MonoBehaviour {
public float speed;
private Rigidbody body;
// Use this for initialization
void Start () {
body = GetComponent<Rigidbody> ();
}
// Update is called once per frame
void Update () {
body.AddForce(transform.forward * speed);
}
void OnCollisionEnter(Collision collision) {
Debug.Log("Collision");
Destroy (this);
}
}
AS you can see this has an OnCollisionEnter
however my object is unable to Collide with anything instead it flys through every object?
This is my prefab
:
And the object im trying to collide with:
Can anyone tell me what ive done wrong?
Upvotes: 0
Views: 67
Reputation: 2187
If you want to use the isTrigger
you need to check the collision with OnTriggerEnter
. If you want to use the OnCollisionEnter
try adding a rigidBody
to the cube with the is kinematic
(for performance) flag, disable the is trigger
from the sphere and see if that works.
Check the difference of the methods here:
https://docs.unity3d.com/ScriptReference/Collider.OnCollisionEnter.html https://docs.unity3d.com/ScriptReference/Collider.OnTriggerEnter.html
Regards
Upvotes: 2