- Home /
Respawn with enemy contact
Hi all, I am a complete beginner at unity with a limited knowledge of coding, I am making a simple maze game and using this tutorial >> http://dma.canisius.edu/~moskalp/tutorials/FollowPlayer/followPlayer.mov have made an object that Im using as the enemy to follow the Player when they get within a certain distance.
I then watched this tutorial http://www.youtube.com/watch?v=xLiSPL2rG3U&feature=fvwrel where he shows how you can make the player respawn when they enter the cube but when I make my cube object "OnTrigger" It falls straight through the ground.
My plan is to make the enemy object respawn the player at the beginning of the maze when they catch up with the player and touch them but I'm getting confused and was wondering if anyone had any suggestions, they would be greatly appreciated thanks!
Your problem is that the cube object falls through the ground ?
Answer by ExTheSea · May 21, 2012 at 01:21 PM
From what i read i think you probably checked IsTrigger what results in ´the object falling through the ground.
You should use a script and probably tags. This is how i would do it.
Make a script and attach it to the players object and write something like this in it:
function OnCollisionEnter(collision : Collision)
{
if(collision.gameObject.tag=="enemy")
{
//Here RespawnScript like for example: gameObject.transform.position=Vector3(0,0,0);
}
}
Then you have to set the tag of the enemy Objects to enemy. Btw. the script is not perfect and you may have to tweak it if you need help with it or if its not working comment and i'll help you or someone else does.
Hope this works.
Hey there, Well done for working out what i was trying to do, I realise now my question a bit unclear. I have tagged the enemy and replaced the (0,0,0) with the coordinates of my player's starting position (was this the wrong thing to do?), It picks up when the player and enemy collide which is brilliant but I then get an error message saying: $$anonymous$$issingFieldException: Field 'UnityEngine.GameObject.position' not found. So i'm guessing everything works perfectly except the respawn script as you predicted but I'm not sure what i would do Thank you this is unbeleivably helpful!
oh yeah right i messed that up a bit try using gameobject.transform.position(your spawnposition).
Would you $$anonymous$$d marking this answer as accepted so that the question doesn't get displayed in unanswered questions anymore.
I'm happy that i did help you.
To get a question marked as answered you have to click that button under the thumbs up and down-thing. When you're not doing this people might think it's not answered.
Your answer
Follow this Question
Related Questions
Send an enemy back to its spawn point using waypoints 2 Answers
How to make this enemy script shoot upwards? 1 Answer
2D Random AI 1 Answer
free roaming enemy ai 1 Answer
enemy respawn after amount of time 2 Answers