- Home /
Collide script not working...
I am coding in javascript and added some stuff to my move script so that when the player falls off the terrain it would hit a large stretched out cube which I tagged "fallout" and would cause the player to "die" and respawn back at the start on the terrain. Here is the script:
var speed : float = 3.0;
var rotateSpeed : float = 3.0;
private var dead = false;
function OnControllerColliderHit (hit : ControllerColliderHit)
{
if(hit.gameObject.tag == "fallout")
{
dead = true;
}
}
function lateUpdate()
{
if(dead)
{
transform.position = Vector3(250.6392,7.611946,19.88934);
gameObject.Find("Main Camera").transform.position = Vector3(0,0,-100);
dead = false;
}
}
@script RequireComponent(CharacterController)
I removed the move section of the script so it only includes the collide sections. At the moment if I run my game and go off the edge the player just lands on the "fallout" and moves around on it, it doesn't respawn like it is supposed to.
The player is a Cylinder scaled (15,1,15) and has a character controller and rigid body. The "fallout" is a cube scaled (5000,5,5000) and has a box collider.
Any help would be greatly appreciated and I need to work this out ASAP as it is for a project that needs to be completed tomorrow.
Thanks.
Answer by GEWLAR · Nov 21, 2013 at 09:17 AM
Is the box collider of the "fallout"-cube marked as "Collider is trigger" ?
If yes, try this script:
function OnTriggerEnter(otherObj: Collider){
if (otherObj.tag == "Player"){
dead=true;
}
}
Attach it to the "fallout"-cube and attach the "Player"-tag to your player. Tell us how it goes
You should accept the answer. This way your question isn't visible in unamswered questions anymore. This would help others to see which questions are answered and which aren't.
Your answer
Follow this Question
Related Questions
Collider script refuses to work 1 Answer
Footstep Audio Check Collider Hitting Floor 1 Answer
How can to convert it on c#? 1 Answer
Door to Next Level HELP! 2 Answers