- Home /
issues with collision detection
I'm currently making a gravity system, and the gravity works great, but the problem is that my collision with my Ground object isn't working at all. Here's the code i have: using UnityEngine; using System.Collections;
public class Gravity : MonoBehaviour
{
public float playerGravity = 5;
void Update ()
{
transform.Translate(Vector3.down * playerGravity * Time.deltaTime);
}
void OnCollisionEnter (Collision col)
{
if(col.gameObject.name == "Ground")
{
playerGravity = 0;
}
}
}
whats wrong with my OnCollisionEnter script?
Collision events are only sent if one of the colliders also has a non-kinematic rigidbody attached. Check for your object component Rigidbody.
Answer by AndrewToth · Sep 20, 2014 at 07:31 AM
I think your game object needs a rigidbody component for collision to work.
Your answer
Follow this Question
Related Questions
Script Wont Take away health from my player when hit by enemy bullet. 0 Answers
Gravity switch not working 0 Answers
Need to talk to a unity developer... this is a rediculous issue. 0 Answers
Bought asset on the asset store and now cannot download it 1 Answer
Instantiate not spawning prefab 2 Answers