- Home /
How to keep an Enemy from teleporting outside of a room.
Simply put, there is an enemy within my game that has the ability to teleport, but what I want is for it to randomly teleport within a certain range, and also make sure that it does not teleport itself outside of the room (or Mesh) it's in at the time. For example, it can teleport any set radius from it's current position at any time, BUT, if where it wants to teleport is outside of the Mesh, it does not do so, but instead chooses another random location in the vicinity that is within the mesh.
How would I go about achieving that with C#?
Also, while this is here, I would also like to how would I go about making the player zoom to where the mouse is clicked? As in, if I were to click on a spot within a distance around the player, the character would suddenly dart to that spot.
Answer by static_cast · Dec 08, 2014 at 12:42 AM
Raycast to the random position to see if it goes through any walls. If not, teleport there.