x


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.

more ▼

asked Aug 08 '12 at 01:00 AM

Cbjfan1 gravatar image

Cbjfan1
37 5 19 29

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...

Aug 08 '12 at 01:24 AM Bunny83

This is somewhat generic, but does get into the placement and planning of zombies and special infected in the L4D game. PDF by Mike Booth of Valve: http://www.valvesoftware.com/publications/2009/ai_systems_of_l4d_mike_booth.pdf

Aug 08 '12 at 03:45 PM irrationalistic

@irrationalistic: This is a great paper from one of my favourite gamedevelopers ;)

Aug 08 '12 at 04:13 PM Bunny83

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

Aug 08 '12 at 06:26 PM Cbjfan1
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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);
more ▼

answered Aug 09 '12 at 03:23 AM

Bunny83 gravatar image

Bunny83
46.8k 12 50 210

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3418
x453
x351
x204
x12

asked: Aug 08 '12 at 01:00 AM

Seen: 480 times

Last Updated: Aug 09 '12 at 03:23 AM