public List <GameObject> initialPathSpawn(Transform pathContainer, ObjectSpawnInfo spawnObject)
    {
        CheckCollisions   template   = spawnObject.gameObject.AddComponent <CheckCollisions>();
        List <GameObject> toBePlaced = new List <GameObject>();

        for (int i = 0; i < spawnObject.count; i++)
        {
            int index = spawnType == PathSpawnType.Cylinderical ? PositionInCylinder(template) : PositionInRectangle(template);
            if (index >= 0)
            {
                GameObject prop = Instantiate(template.gameObject, template.transform.position, template.transform.rotation, ContainerFromSegmentNumber(pathContainer, index));
                ScaleRotateProp(prop, spawnObject);

                prop.transform.localScale = new Vector3(prop.transform.localScale.x / prop.transform.parent.localScale.x, prop.transform.localScale.y / prop.transform.parent.localScale.y, prop.transform.localScale.z / prop.transform.parent.localScale.z);

                prop.name = template.gameObject.name + " " + i;
                prop.GetComponent <CheckCollisions>().ignoreEnvironmentCollisions = true;
                toBePlaced.Add(prop);
            }
            else
            {
                Debug.Log("Missing path, you need to have one generated before placing path objects.");
                break;
            }
        }
        return(toBePlaced);
    }
    public int PositionInRectangle(CheckCollisions position)
    {
        if (path.primaryPath.segments.Count == 0)
        {
            return(-1);
        }

        List <LineSegment> allSegments   = AllSegmentsFromPath();
        LineSegment        randomSegment = RandomEquallyDistributedSegment(allSegments, path.minlength, path.maxLength);
        int randomIndex = allSegments.IndexOf(randomSegment);

        Vector3 randPointOnTri = RandomPointInRectangularPrism(randomSegment.start, randomSegment.end, pathWidth, pathHeight);

        position.SetNewLocation(randPointOnTri, Quaternion.identity);

        return(randomIndex);
    }
    private int PositionOnMeshRandomizer(GameObject[] spawnSurfaces, CheckCollisions position, ObjectSpawnInfo info)
    {
        if (spawnSurfaces.Length == 0)
        {
            return(-1);
        }

        int randomMeshIndex = Random.Range(0, spawnSurfaces.Length);

        if (spawnSurfaces[randomMeshIndex].GetComponent <MeshFilter>())
        {
            int[]     tris  = spawnSurfaces[randomMeshIndex].GetComponent <MeshFilter>().sharedMesh.triangles;
            Vector3[] verts = spawnSurfaces[randomMeshIndex].GetComponent <MeshFilter>().sharedMesh.vertices;

            int randomTris = Random.Range(0, Mathf.RoundToInt(tris.Length / 3f));

            Bounds bounds = spawnSurfaces[randomMeshIndex].GetComponent <MeshFilter>().sharedMesh.bounds;

            Vector3 a = spawnSurfaces[randomMeshIndex].transform.TransformPoint(verts[tris[randomTris * 3]]);
            Vector3 b = spawnSurfaces[randomMeshIndex].transform.TransformPoint(verts[tris[(randomTris * 3) + 1]]);
            Vector3 c = spawnSurfaces[randomMeshIndex].transform.TransformPoint(verts[tris[(randomTris * 3) + 2]]);

            Vector3 side1  = b - a;
            Vector3 side2  = c - a;
            Vector3 normal = Vector3.Cross(side1, side2);

            float randX = Random.value;
            float randY = Random.value;
            float randZ = Random.value;

            Vector3    randPointOnTri = (randX * a + randY * b + randZ * c) / (randX + randY + randZ);
            Quaternion rotation       = Quaternion.FromToRotation(Vector3.up, normal.normalized);

            position.SetNewLocation(randPointOnTri, rotation);
            position.transform.RotateAround(position.transform.position, position.transform.up, Random.Range(0, 360));
            return(randomMeshIndex);
        }
        else
        {
            return(-1);
        }
    }
Exemple #4
0
    private void OnTriggerStay(Collider other)
    {
        isColliding = true;

        if ((ignoreEnvironmentCollisions && other.tag == "Ignorable") || other.transform == this.transform.parent)
        {
            isColliding = false;
        }
        if (other.transform.parent)
        {
            CheckCollisions otherCollisionScript = other.transform.parent.GetComponent <CheckCollisions>();
            if (otherCollisionScript && otherCollisionScript.order > order && !invalid)
            {
                isColliding = false;
            }
            else
            {
                invalid = true;
            }
        }
    }
    public List <GameObject> initialStaticSpawn(GameObject[] spawnSurfaces, ObjectSpawnInfo spawnObject)
    {
        List <GameObject> toBePlaced = new List <GameObject>();

        for (int i = 0; i < spawnObject.count; i++)
        {
            if (spawnSurfaces.Length > 0)
            {
                GameObject prop = Instantiate(spawnObject.gameObject, spawnObject.gameObject.transform);

                CheckCollisions collisionScript = prop.GetComponent <CheckCollisions>() ? prop.GetComponent <CheckCollisions>() : prop.AddComponent <CheckCollisions>();
                int             index           = PositionOnMeshRandomizer(spawnSurfaces, collisionScript, spawnObject);
                if (index >= 0)
                {
                    prop.transform.parent = spawnSurfaces[index].transform;

                    collisionScript.order = order;
                    order++;

                    prop.transform.localScale = new Vector3(spawnObject.gameObject.transform.localScale.x / spawnSurfaces[index].transform.localScale.x, spawnObject.gameObject.transform.localScale.y / spawnSurfaces[index].transform.localScale.y, spawnObject.gameObject.transform.localScale.z / spawnSurfaces[index].transform.localScale.z);

                    ScaleRotateProp(prop, spawnObject);


                    prop.name = spawnObject.gameObject.name + " " + i;
                    prop.tag  = "Environmental";
                    toBePlaced.Add(prop);
                }
                else
                {
                    DestroyImmediate(prop);
                }
            }
            else
            {
                Debug.Log("There are no current spawn surfaces, must be created before object placement.");
            }
        }
        return(toBePlaced);
    }
Exemple #6
0
 private void Start()
 {
     rb = GetComponent <Rigidbody>();
     _checkCollisions = GameObject.Find("Player").GetComponent <CheckCollisions>();
 }
/*
 * jump behaviour:
 * -add timer for when a second jump can be made, ?? check y velocity < 0 and timeb4nextjump < currenttime??????????????
 *
 * wallSlide:
 * -if player is wallsliding and tries to jump add force in opposite direction
 * -??if player is wallsliding and tries to jump with oppositie direction either mimic above behaviour or add slight boost in jump??
 *
 * Run:
 *
 * Attack:
 */

    private void Start()
    {
        rb             = GetComponent <Rigidbody2D>();
        collisions     = new CheckCollisions(feet, wallCheck);
        numOfJumpsUsed = maxJumps;
    }
Exemple #8
0
 private void Start()
 {
     _checkCollisions = GameObject.Find("Player").GetComponent <CheckCollisions>();
 }