- Home /
Random Player Respawn Points
Ok i want it so when the game starts all players respawn from different locations. Like everyone kills each other, they respawn different places, teams they spawn near each other if the are teammates but enemies far away.
Answer by lil_billy · May 16, 2011 at 05:17 AM
well have fun with that
there a ton of different ways to go about it i cant tell you the most efficient method since id need to play with it myself but i guess you could use dist checks or my favorite, Trigger colliders
and like if a player enters a range of a spawn point it sends a message to a command_cube (what i call my objects that are placed simply for holding world governing scripts) that message contains the players team type and what SP he got near
then when a player dies a script on the player asks the cube where to spawn and it goes from there looking at the last known coord of a teammate
after that you just use Random.Range for any randomness you want
Answer by DaveA · May 16, 2011 at 06:17 AM
What I do is create empty game objects named 'SpawnPoint' into a parent game object called 'SpawnPoints' and place them around my scene. When I need to spawn something, I find the SpawnPoints object and then pick a random child of that ( a random spawn point), and use its transform for position and orientation. I also created a Gizmo that has an arrow to show the orientation, so I can more easily see how the player will be looking when it appears there.
Answer by Dreamer · May 16, 2011 at 06:22 AM
Below is the script give you idea how to do it:
var respawn_x:float; var respawn_y:float;
function Respawn(friendly:boolean){ if(friendly){ respawn_x=Random.Range(-100,0); respawn_y=Random.Range(-100,100); } else{ respawn_x=Random.Range(0,100); respawn_y=Random.Range(-100,100); }
Instantiate (player_prefab, Vector3(respawn_x, respawn_y, 0), Quaternion.identity);
}
Your answer
Follow this Question
Related Questions
Player starts instantiate at random places? 3 Answers
Making the delay actually work 1 Answer
How do I spawn a random prefab? 1 Answer
Player Respawn with Joystick 2 Answers
Player Respawn Script - Not Working 1 Answer