- Home /
Cant get Collisions to work
I know collisions have changed a little bit in unity 5 but i cant seem to get this to work at all
im making a 3d rail shooter, and there are objects on the ground that when the players ship collides with, are supposed to subtract health from the player.
the players ship is an empty game object, with the prefab for the ship as a child which has a rigidbody(isKinematic on) and a box collider(not trigger)
the object the player is colliding with is a prefab of an arch (that i removed the mesh collider from) this has a child which is an empty gameobject that i attached the rigidbody (isKinematic on) and the two scripts(one of which should decrease the players health) This emptyGameObject has 5 empty game objects as children, each of which has a box collider(each one is for a different part of the arch). the box colliders are currently not set to isTrigger.
these are the two scripts i attached to my parent game object that is holding all of the box colliders
using UnityEngine;
using System.Collections;
public class DamagePlayerOnCollision : MonoBehaviour{
public float damageAmount = 1.0f;
public float coolDownTime = 1.0f;
private bool inCoolDown = false;
void onCollisionEnter()
{
Debug.Log ("COLLIDED!!!!!!!!!!!!!!!!!!!");
if (!inCoolDown) {
HealthManager.Instance.DamagePlayer (damageAmount);
inCoolDown = true;
Invoke ("Uncool", coolDownTime);
}
}
void Uncool()
{
inCoolDown = false;
}
}
and here is the other one
using UnityEngine;
using System.Collections;
public class DamagePlayerOnTrigger : MonoBehaviour{
public float damageAmount = 1.0f;
public float coolDownTime = 1.0f;
private bool inCoolDown = false;
void onTriggerEnter()
{
Debug.Log ("COLLIDED!!!!!!!!!!!");
if (!inCoolDown) {
HealthManager.Instance.DamagePlayer (damageAmount);
inCoolDown = true;
Invoke ("Uncool", coolDownTime);
}
}
void Uncool()
{
inCoolDown = false;
}
}
i am aware that only one of these codes should be used for this to work, however, neither one of them does and Debug.Log never prints anything when the players ship collides with the object. What do i need to do for the game to recognize the collisions(Again, I am using Unity 5, not 4).
Answer by Vice_Versa · Apr 14, 2015 at 09:19 PM
so i figured out what was wrong. i spelled onCollisionEnter with a lowercase o it shouldve been OnCollisionEnter()
Answer by Digital-Phantom · Apr 08, 2015 at 10:00 AM
Firstly, try changing the box colliders to isTrigger.
Answer by Johnz1234 · Apr 08, 2015 at 10:48 AM
Trigger your object and its shoud work fine
so i tried triggering the objects then turning those off and triggeringthe object, neither worked. then i tried removing the empty game object holding all the colliders and made them children of the main object holding the prefab. if i have is$$anonymous$$inemetic off, use gravity off, and i jam the arch halfway through the gameplane, it collides(bounces off) of the ship without flying through the air, however neither of my scripts are being run when the collision happens. im using the methods onTriggerEnter and onCollisionEnter should i be trying to use something else?
Your answer
Follow this Question
Related Questions
seeking collision scenario solution : falling anvil vs. player 0 Answers
Rigidbody goes crazy when isKinematic is false 1 Answer
How do I change Raycast's direction based on movement input? 1 Answer
Collisions when pushing object 1 Answer
Kinematics: Trying to get an object to land at a known point 1 Answer