- Home /
Collision not being detected?
I have had a problem with a collision detection that is meant to cause a few events to take place, but the collision itself is not being registered so the events are not being triggered.
this is the first code for the first collision (of 2):
”
var Collectible2 : GameObject; var GUI1 : GUIText;
function OnCollisionEnter( collision : Collision ) { if ( collision.gameObject.Name == “Graphics” ) { Debug.Log( “Collision: Detected (Graphics)” ); Destroy( gameObject.Find(“Collectable1″) ); transform.GUI1.Text( “Well Done!” ); yield WaitForSeconds(5); Collectible2.MeshRenderer.Enabled = true; Collectible2.Collectible2Script.Enabled = true; Collectible2.ParticleRenderer.Enabled = true; transform.GUI1.Text( “Now Find The Second Collectible >:D” ); yield WaitForSeconds(5); transform.GUI1.Text( “” ); } } ”
and this is the second (Not sure if this one isn’t working as that code is meant to set it off):
”
var EndGame : String;
function OnCollisionEnter(EndGameCollision : Collision) { if(EndGameCollision.gameObject.name == “Graphics”) { Application.LoadLevel(EndGame); Debug.Log(“Collision: Detected (Graphics)”); } } ”
I also originally had all of the script on one document:
”
var readynow : boolean = true; var seconds : float = 5; var gui : GUIText; var nextlevel : String; var collectible1 : GameObject; var collectible2 : GameObject; var Spawnpoint : GameObject;
function OnCollisionEnter(Collectible : Collision) { if(Collectible.gameObject.name == “floor2″) { Debug.Log(“Collision: Detected”); } if(Collectible.gameObject.name == collectible1) { Debug.Log(“Collision: Detected”); destroy(); create(); GUIdisplay(); if(Collectible.gameObject.name == collectible2) { Debug.Log(“Collision: Detected”); destroy2(); } } }
function destroy() { readynow=false; Destroy(gameObject.Find.collectible1); yield WaitForSeconds(seconds); Destroy(gameObject.Find.Spawnpoint); } function create() { readynow=false; Instantiate(gameObject.Find.collectible2, Spawnpoint.position, Spawnpoint.rotation);
} function GUIdisplay() { transform.gui.Text(“Well Done! Now Find The Second Collectable”); } function destroy2() { readynow=false; Destroy(gameObject.Find.collectible2); Application.LoadLevel(nextlevel); } ”
but I don’t need that one analysing, just the other two (albeit more efficient, I am a beginner so I should probably just stay with the other two)
So, what can I do to fix these problems?
thanks, Tim
edit your post, highlight each portion that is your code/script and clicky the 101010 button, you can't read(don't want to try) that up there.
Answer by DeBunked · Feb 08, 2013 at 05:57 PM
Make sure one of the colliding objects has a rigid body attached to it.
Rigidbody has nothing to do with collision issues. Rigidbody is for physics.
Rigidbodies do play a part in several forms of collisions, especially ones that make use of PhysX.
http://docs.unity3d.com/Documentation/Components/class-$$anonymous$$eshCollider.html (table at the bottom for further reference)
Your answer
Follow this Question
Related Questions
Getting sprites to stop going through one another? 1 Answer
Collision Enter one of the objects ? 1 Answer
Obstacle avoidance 1 Answer
Collision detection for sprite 1 Answer
How does Unity detect collision? 0 Answers