Ok I know this is probably a simple solution to this. And I tried to solved myself.. But I need some help before my head explodes, or I have a stroke. I more of a graphics guy.... I working on very simple collisons. Basically I'm using the "First Person Controller" for the player I have added a simple cube(From Unity). I added Rigidbody to the cube. Basically I am trying to get it when so that when the player collides with the box. A message would display in the debug log. I have written this script (javascript) and added it to the cube. Code (csharp): function OnCollisionEnter(collision:Collision){ if (collision.gameObject.tag == "Player") { print ("yay it works); } } I get no errors, but I also get no display in the console/debug log. So basically nothing is happening. Is their something wrong with the code? Can I get some help please?
Just a quick guess, but it looks like you're missing a parenthesis: Code (csharp): function OnCollisionEnter(collision:Collision){ if (collision.gameObject.tag == "Player") { print ("yay it works"); // missing parenthesis here } }
ty for the reply.. Yeah the parenthesis is there, that just a mistype on my part sorry.. any help I been searching, i just cant find a solution...
Hi! maybe this can help. Character Controller: http://unity3d.com/support/documentation/Components/class-CharacterController.html "The Controller does not react to forces on its own and it does not automatically push Rigidbodies away." Some code i found somewhere some time ago! Code (csharp): //CharacterCollider.js // this script pushes all rigidbodies that the character touches var pushPower = 2.0; function OnControllerColliderHit (hit : ControllerColliderHit) { var body : Rigidbody = hit.collider.attachedRigidbody; //print("START"); var a_layer = hit.collider.gameObject.layer; if (a_layer != 8 ) return; // no rigidbody if (body == null || body.isKinematic) return; // We dont want to push objects below us if (hit.moveDirection.y < -0.3) return; // Calculate push direction from move direction, // we only push objects to the sides never up and down var pushDir = Vector3 (hit.moveDirection.x, 0, hit.moveDirection.z); // If you know how fast your character is trying to move, // then you can also multiply the push velocity by that. var p = (pushPower-body.mass); print(p); if (p < 0 ) pr=0; // Apply the push body.velocity = pushDir * p; } Credists to the maker whoever you are
thanks to everyone I figured out the problem. I added a box collider to the Player, and now it works. For some reason I was assuming that I only needed character controller, but I guess I was wrong. I knew it was something simple lol.