- Home /
How to make enemy teleport right next to player?
I am making a horror game and was wondering how to make an enemy appear (teleport) right next to the player, to scare them. There is only one enemy in the house, so i need the enemy to teleport instead of just spawning next to the player. Any ideas on how to do this?
Answer by Radon · Aug 03, 2012 at 01:28 AM
     function Update () {
     transform.position = Vector3(X, Y, Z); //change x, y, z to where you want 
     yieldWaitForSeconds(2);
     transform.position = Vector3(X, Y, Z); //change x, y, z to somewhere where it's not visible for your controller. 
       } 
     }
Answer by Radon · Aug 02, 2012 at 06:39 AM
I'm not sure if this works. I just wrote it down. But try it. If not, I will give you another way.
 function Update ()
 {
  transform.position = Vector3(X, Y, Z); //change x, y, z to where you want
 }
Is there any way I can make it so the enemy only appears for a split second and then disappears?
You could use the yield WaitForSeconds(2); and give it a new command or function or even repeat the above code with different coords like this.
function Update () { transform.position = Vector3(X, Y, Z); //change x, y, z to where you want yield WaitForSeconds(2); function Update () { transform.position = Vector3(X, Y, Z); //change x, y, z to somewhere where it's not visible for your controller. } }
I was kind of hoping I could gear it more towards this question. I made a new question to try and clarify before you posted.
http://answers.unity3d.com/questions/295136/make-enemy-appear-in-front-of-player-and-then-disa.html
Answer by djfunkey · Oct 05, 2012 at 07:52 AM
     public Transform ScaryMonster;
     public Transform ScaredPlayer;
     public int FirstAppear = 0;
     
     private int MonsterStayTime = 1;
     public int Random1;
     public int Random2;
     private Random RandomTime;
     
     void Update ()
     {
         RandomTime = Random.Range(Random1, Random2);
         FirstAppear += Time.time;
         
         if (FirstAppear = 20)
         {
             Transform scarymonster;
             scarymonster = Instantiate (ScaryMonster, ScaredPlayer.position, scarymonster.LookAt(ScaredPlayer)) as Transform;
             Destroy (ScaryMonster, MonsterStayTime);
             Random1 = 30;
             Random2 = 40;
         }
         if (RandomTime <= Time.time)
         {
             scarymonster = Instantiate (ScaryMonster, ScaredPlayer.position, scarymonster.LookAt(ScaredPlayer)) as Transform;
             Destroy (ScaryMonster, MonsterStayTime);
             Random1 = 80;
             Random2 = 90;
         }
         if (RandomTime <= Time.time)
         {
             scarymonster = Instantiate (ScaryMonster, ScaredPlayer.position, scarymonster.LookAt(ScaredPlayer)) as Transform;
             Destroy (ScaryMonster, MonsterStayTime);
             Random1 = 120;
             Random2 = 130;
         }
         /* you get the drift, you just have to copy the above code multiple times for how ever many times you want */
     }
Answer by Rixterz · Aug 29, 2013 at 12:07 AM
You could attach this to your enemy:
 var Player : Transform;
 function Start(){
 Teleport();
 }
 function Teleport(){
 yield WaitForSeconds(10);
 transform.position = Vector3(Player.position.x - 5, Player.position.y - 5, Player.position.y);
 yield WaitForSeconds(0.5);
 renderer.enabled = false
 }
This will wait for 10 secs, then teleport behind the player for 0.5 secs, then hide. To make the enemy teleport in front of the player, change "- 5" to "+ 5"
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                