Beispiel #1
0
    // orient for collidables which have a platform as a parent
    public virtual void orient(PlatformObject parent, Vector3 position, Quaternion rotation)
    {
        thisTransform.parent = parent.getTransform();
        Vector3 pos = startPosition;

        pos += position;
        thisTransform.localPosition = parent.getTransform().InverseTransformPoint(pos);
        thisTransform.rotation      = startRotation;
        thisTransform.Rotate(0, rotation.eulerAngles.y, 0, Space.World);
    }
Beispiel #2
0
    public bool aboveTurn()
    {
        RaycastHit hit;

        if (Physics.Raycast(thisTransform.position + Vector3.up / 2, -thisTransform.up, out hit, Mathf.Infinity, 1 << platformLayer))
        {
            PlatformObject platform = hit.collider.GetComponent <PlatformObject>();

            // don't allow a turn if the player is trying to do a 180 degree turn
            if (Mathf.Abs(thisTransform.eulerAngles.y - platform.getTransform().eulerAngles.y) > 0.1f)
            {
                return(false);
            }

            if (platform != null)
            {
                return(platform.isRightTurn || platform.isLeftTurn);
            }
        }

        return(true);
    }
    // returns true if there is still space on the platform for a collidable object to spawn
    private void spawnCollidable(ObjectType objectType, Vector3 position, Vector3 direction, ObjectLocation location, PlatformObject platform, int platformLocalIndex, bool activateImmediately)
    {
        int collidablePositions = platform.collidablePositions;
        // can't do anything if the platform doesn't accept any collidable object spawns
        if (collidablePositions == 0)
            return;

        Vector3 offset = platformSizes[platformLocalIndex] * 0.1f;
        float zDelta = platformSizes[platformLocalIndex].z * .8f / (1 + collidablePositions);

        for (int i = 0; i < collidablePositions; ++i) {
            if (platform.canSpawnCollidable(i)) {
                spawnData.slotPositions = platform.getSlotsAvailable();
                int localIndex = infiniteObjectManager.getNextObjectIndex(objectType, spawnData);
                if (localIndex != -1) {
                    CollidableObject collidable = infiniteObjectManager.objectFromPool(localIndex, objectType) as CollidableObject;
                    Quaternion lookRotation = Quaternion.LookRotation(direction);
                    Vector3 spawnSlot = collidable.getSpawnSlot(platform.getTransform().right * slotDistance, spawnData.slotPositions);
                    collidable.orient(platform, position + (offset.z + ((i + 1) * zDelta)) * direction + spawnSlot, lookRotation);
                    if (activateImmediately)
                        collidable.activate();
                    
                    int objectIndex = infiniteObjectManager.localIndexToObjectIndex(localIndex, objectType);
                    infiniteObjectHistory.objectSpawned(objectIndex, (offset.z + ((i + 1) * zDelta)), location, lookRotation.eulerAngles.y, objectType);
                    platform.collidableSpawned(i);

                    // don't allow any more of the same collidable type if we are forcing a different collidable
                    if (platform.forceDifferentCollidableTypes)
                        break;
                }
            }
        }
        spawnData.slotPositions = 0;
    }
Beispiel #4
0
 // orient for collidables which have a platform as a parent
 public virtual void orient(PlatformObject parent, Vector3 position, Quaternion rotation)
 {
     thisTransform.parent = parent.getTransform();
     Vector3 pos = Vector3.zero;
     float yAngle = rotation.eulerAngles.y;
     pos.Set(startPosition.x * Mathf.Cos(yAngle * Mathf.Deg2Rad) + startPosition.z * Mathf.Sin(yAngle * Mathf.Deg2Rad), startPosition.y,
             -startPosition.x * Mathf.Sin(yAngle * Mathf.Deg2Rad) + startPosition.z * Mathf.Cos(yAngle * Mathf.Deg2Rad));
     pos += position;
     thisTransform.localPosition = parent.getTransform().InverseTransformPoint(pos);
     thisTransform.rotation = startRotation;
     thisTransform.Rotate(0, rotation.eulerAngles.y, 0, Space.World);
 }