- Home /
Left 4 Dead-style Spawnpoints?
Hi everyone. I need help with making a game where one person has to get to the other side of the map, and the other person tries to stop him. The person trying to stop him can choose from physical being, or paranormal. Physical being opens up several monsters to choose from. I have all the players set up, I just need some help with the classes and spawning.
I'm not sure what kind of help do you expect? It depends on your gamedesign how you want the spawnpoint selection.
For example here's an interactive simulation where a player can spawn in Quakelive(Campgrounds) that you have fragged.
Do you want them to spawn between the survivors and the final target? Does the map has some kind of path? There are hundreds of variables which you have to define before you start to implement a certain spawn rule.
Do you remember? Clear and detailed questions...
This is somewhat generic, but does get into the placement and planning of zombies and special infected in the L4D game. PDF by $$anonymous$$ike Booth of Valve: http://www.valvesoftware.com/publications/2009/ai_systems_of_l4d_mike_booth.pdf
@irrationalistic: This is a great paper from one of my favourite gamedevelopers ;)
I'm trying to keep it simple. The humans spawn of one side of the map, the creatures on the other. All I need help of is a sort of "Selection menu" for each of the playable people
Answer by Bunny83 · Aug 09, 2012 at 03:23 AM
Well, since you actually don't want Left4Dead style spawnpoints but simple multiplayer spawnpoints, you can use something like that:
// C#
// SpawnPoint.cs
using UnityEngine;
using System.Collections.Generic;
using System.Linq;
public enum Team
{
Survivor,
Infected
}
public class SpawnPoint : MonoBehaviour
{
// players should be on custom layer 8 so they can be
// detected if they block a spawn point
private static int m_PlayerLayer = 8;
// range around the spandpoint which should be empty to use this spawn point
private static float m_ClearRadius = 2.0f;
// Set in the inspector
public Team team = Team.Survivor;
public bool IsThisPointClear()
{
var players = Physics.OverlapSphere(transform.position, m_ClearRadius, 1 << m_PlayerLayer);
return players.Length <= 0;
}
public static SpawnPoint FindFreeSpawnPoint(Team aTeam)
{
var spawns = FindObjectsOfType(typeof(SpawnPoint)).Cast<SpawnPoint>().Where(O => O.team == aTeam).ToList();
while (spawns.Count > 0)
{
int i = Random.Range(0,spawns.Count);
if (spawns[i].IsThisPointClear())
return spawns[i];
spawns.RemoveAt(i);
}
return null;
}
}
Just place some empty gameobjects in the scene, attach this script and select the team for each spawnpoint.
Now you can simply use this when ever you need a spawn point:
var SP = SpawnPoint.FindFreeSpawnPoint(Team.Survivor);
if (SP == null)
{
Debug.LogError("All spawns occupied and / or not enough spawn points");
return;
}
Instantiate(playerPrefab, SP.transform.position, SP.transform.rotation);
Your answer
Follow this Question
Related Questions
How do we create a custom class in scripting? 1 Answer
Spawn object problem 1 Answer
Inspector button for custom class 1 Answer