- Home /
using OnTriggerEnter, char falls thru respawn point
So I have a cube that I stretched out under my racetrack to catch my character when it falls off the track. For my character, I'm using a character controller. For the cube, I'm using a box collider. I also have a respawn point located on the track that's a cylinder that also uses a box collider. I have attached the following code to my cube to catch my character (and I dragged the cylinder in as the Spawn):
var spawn : Transform; //drag spawn point to here in the inspector
function OnTriggerEnter(other : Collider) { if (other.tag == "Player") { other.transform.position = spawn.position; } }
Now here's the problem. When my character respawns, it is taken to the general area of the cylinder, but it immediately falls through it and falls through the track. I don't understand why this would be because both hold him just fine when the game starts out. The track has a mesh collider. Also, just to try some things, I attempted moving the cylinder up above the track--didn't help. Any ideas? Thanks.
Are your GameObject with the tag "Player" the root parent of the player?
I'm not really sure what you mean. 3rd Person Controller is the thing that displays in the hierarchy. Under it are Bip001, construction_worker, and myCharacter. I have it so the construction worker is invisible, but my character is the one that displays and moves. $$anonymous$$y character isn't animated. I have 3rd Person Controller tagged as Player, but I've also experimented with tagging all of them as Player, but that doesn't help.
please post your comments as a comment not an answer :) hmm, then it sounds wierd, have you tried pausing the editor as soon as a respawn occours to make sure that all components are as they should, and that you player collider is above the track collider etc.
I haven't tried pausing it yet. I didn't think of it because it goes so fast. I will try it tomorrow when I get back to my computer. But if it's not in the right place, I'm not sure what I can do because it's correct before the action occurs.
Okay so after pausing it, I could tell it was respawning too low. So I moved the cylinder way higher than it should be, and it worked. But it's doing a different strange thing that I can see now. $$anonymous$$y character respawns standing inside of the cylinder, even though the cylinder has a box collider on it and my character is able to stand on top of the cylinder at the beginning of the game. What am I doing wrong? Thanks.
Answer by hrlarsen · Mar 20, 2013 at 07:14 PM
Just posting as answer now for others to benefit. Make sure that your collider is spawning above the track collider, you can see this by pausing the game when the respawning is done and see the state.
As for the other problem. Try to disable the Mesh Renderer on the cylinder (my guess is that you don't want to show it) and then make sure that your character has no collider, charactercontroller or rigidbody (these could be attached to the Root object if needed). Then you would have the character as a child of the "Player Object"
Your answer
Follow this Question
Related Questions
Moving a gameObject to the position of an empty gameObject 2 Answers
Need help with respawn after falling. 3 Answers
Trouble with a respawn script 1 Answer
character gravity problem 1 Answer
Check for Collision 1 Answer