- Home /
Collision Help Please
So I've searched far and wide for a solution to my problem and seems I'm at a loss. If you rage me for not searching hard enough, I'll bash your face in. I'm at my wits end on this issue, and has halted my games development.
On a lighter note... My character "Player" is named & tagged as "Player"(Seen below) -Ridgedbody applied, and "CollisionChange1.js" is attached to him.
CollisionChange.js :
#pragma strict
function OnCollisionEnter(other : Collision){
if(other.gameObject.name == "Cave1Entrance"){
Debug.Log("Collided with " + other.gameObject);
//Application.LoadLevel("cave1");
}
if(other.gameObject.tag == "Cave1Entrance"){
//Application.LoadLevel("cave1");
Debug.Log("Collided with " + other.gameObject);
}
}
I'm using a 1x1 cube for my "Cave Entrance" until I can get this working properly, then I'll delete this 1x1 cube and rename my original cave entrance to "Cave1Entrance". (Example Below of names/tags/etc)
Yes, my build settings are completed. Eyden (0), cave1 (1)
Ugh, a little help would be a huge relief... Thanks guys.
Is OnCollisionEnter beeing called? Check this with a Debug statement at the very top of the function, not inside of the if condition.
If the first debug shows up, but the second doesn't, then the collision works fine but the if condition is false. This would mean that you likely misspelled the name of your cave entrance gameobject.
If neither is shown the function does not get called. This can have various causes: $$anonymous$$ake sure both your player and the cave entrance have a collider attatched. Also make sure they can collide. Check out the collision matrix as reference.
A generall advice for organization purpose: Have your cave enter logic on the entrance not on the player. Just give it some OnCollision/OnTrigger statement and check if the tag of the other thing is player. That way every thing knows what it does on its own and the player does not have a list of a hundred conditions to check what should happen on collisions.
So this is what I've changed my code to.
#pragma strict
function OnCollisionEnter(other : Collision){
Debug.Log("Collided with " + other.gameObject);
if(other.gameObject.name == "Cave1Entrance"){
Debug.Log("Collided with " + other.gameObject);
//Application.LoadLevel("cave1");
}
if(other.gameObject.tag == "Cave1Entrance"){
//Application.LoadLevel("cave1");
Debug.Log("Collided with " + other.gameObject);
}
}
I have a rigidbody on my Player (Enabled)
Box collider is on my cave entrance (Enabled)
The CollisionChange.js is on my "Player"
Box is named "Cave1Entrance", tagged "Cave1Entrance" (No spelling errors.)
So tell me, what could POSSIBLY cause this to mess up if there are no other factors?!?!?
I've tried ticking "IsTrigger", but the Collider seems void, i can walk through it, nothing happens.
I've read the entire Physics Components Guide and to no avail.
It's a shame that I've spent 8 weeks on a full planet level design, and when it comes time to add a new planet, issues. I'm nearly to the point of deleting the entire project and saying F*&^ it.
What kind of collider is on your player and how fast is it moving? Also, is the cave entrance marked static?
I've got a capsule collider on my character (I've tried capsule, box, sphere, rigidbody, everything.) 8 $$anonymous$$ove speed according to the "PlatformInputController" And there is a box collider on my cave entrance.
Neither is static.
Also, the Debug.Log isn't showing any results of OnCollisionEnter being called.... Hmmm.... It's the only other script on my player besides the PlatformInputController.
Answer by Brian@Artific · Jul 11, 2013 at 09:24 PM
EDIT: This answer has been changed based on the new information in your comment regarding use of the CharacterMotor script:
The CharacterMotor script requires a CharacterController, which is a special type of collider. To detect collisions resulting from calls to the CharacterController's Move method, you'll need to use the OnControllerColliderHit method instead of OnCollisionEnter.
You sir, $$anonymous$$@Floppy, are a God.
Worked a charm. Thanks a billion. Sol Source development continues!
Can you please accept this answer then? This will help people with the same problem find the answer faster and people who want to help won't run into a solved problem. Thanks.
Your answer
Follow this Question
Related Questions
super mario pipe physics? 1 Answer
Trouble with OnCollisionEnter and Exit 1 Answer
Trigger Enter and Exit not working properly? 2 Answers
destroy touch the screen on gameobject in camera 0 Answers
Audio play when object hit collision. 2 Answers