- Home /
What could cause aberrant collision callbacks in Unity4?
Hi,
We're using the Goldstone book in our intro to 3D Game Development course and have ran into an odd bug. It appears to be an engine bug but I was wondering if anyone else has seen it and might know what causes it or how to prevent it.
Semi-randomly, my students can get a collision with the all the power cells to trigger at the same time even though their player controller is nowhere near some of the power-cells at the time.
Ive examined it up, down and sideways, put debugging logging in the code and it really just seems to be a pathological event thrown on Unity's part. So far, we've only see the effect on Windows.
Any confirmation and/or workarounds would be much appreciated.
Edit Addl:
Here is the script that is firing aberrantly:
using UnityEngine;
using System.Collections;
public class PowerCell : MonoBehaviour {
public float rotationSpeed = 100f;
public bool collected;
// Use this for initialization
void Start () {
collected=false;
}
// Update is called once per frame
void Update () {
transform.Rotate(new Vector3(0,rotationSpeed*Time.deltaTime,0));
}
void OnTriggerEnter(Collider col) {
Debug.Log ("power cell trigger "+ gameObject.name);
if(col.gameObject.tag=="Player") {
if(!collected) {
col.gameObject.SendMessage("CellPickup");
Destroy(gameObject);
col.gameObject.SendMessage("HUDon");
collected=true;
}
}
}
}
The entire project can be downloaded at:
https://www.dropbox.com/s/v22f9h62qcqa7co/Island%20Unity%20Project.zip
These are the best reproduction instructions we coudl coem up with:
Sometimes, when walking around, the power cells are picked up even though the player controller is not colliding with each object. This occurs while walking either next to or on the outpost or on the ground in the area around the outpost where each power cell is located.
Note that when he says "not colliding' he means that he shouldn't be colliding. We DO see collision call back on every objet individually.
You really need to post more information such as the script you are using. Unless somebody has read that specific book, your question will go unanswered.
Hey Jeff,
It would be of great help if you could post the script that you are having problems with. It would help us help you better. It could very well be an engine problem but im not aware of a bug like that in Unity 4. If we could take a look at the script we can see if there may be anything there that could be causing it. Thanks!
Sure, Ill post the script up. Do you want the whole project too?
Just a note, I wont have the script up til Thursday because thats the next time Ill be on campus.
@Doireth Its the most commonly mentioned book on Unity in the entire community, so I thought that was self-explainatory. here's the Amazon link