示例#1
0
    // TODO: SET UP CAMERA SCRIPT WHICH WILL MAKE THE CAMERA ZOOM A LITTLE OUT WHILE BOL IS FAR AWAY (ORI)

    void Start()
    {
        MasterController.Instance.CheckPointReached          += RecordCurrentState;
        MasterController.Instance.RevertToPreviousCheckPoint += RevertToPreviousCheckPoint;
        // originalLocalScaleX = transform.localScale.x;
        rayCastOrigins.HorizontalRayCount = 5;
        rayCastOrigins.VerticalRayCount   = 4;
        ChangeAnchorPosition();

        Collisions.UpdateRayCastOrigins(physicalCollider, ref rayCastOrigins);
        Collisions.CalculateRaySpacing(physicalCollider, ref rayCastOrigins);
        DarknessParticles[] darknesses = FindObjectsOfType <DarknessParticles>();
        for (int i = 0; i < darknesses.Length; i++)
        {
            darknesses[i].PlayerIsInsideMe += BeDarkened;
        }
        //Physics.IgnoreCollision(balloflight.GetComponent<Collider>(), GetComponent<Collider>(),true);
    }
    protected override void Update()
    {
        base.Update();
        //Vector3 newDestination;
        Collisions.UpdateRayCastOrigins(collider, ref rayCastOrigins); //maybe we shouldnt do this every Move()
        Collisions.CalculateRaySpacing(collider, ref rayCastOrigins);  //maybe we shouldnt do this every Move()
        if (beingInteractedWith)
        {
            isAmplified = true;
        }

        if (isAmplified)
        {
            if (VerticalCollisions() != null)
            {
                isAmplified = false;
            }
            if (Vector3.Distance(parent.transform.position, currentDestination) < SMALL_DISTANCE)
            {
                //change destination
                currentDestinationIndex++;
                if (currentDestinationIndex >= amplifiedTransforms.Length)
                {
                    currentDestinationIndex = 0;
                }
                currentDestination = amplifiedTransforms[currentDestinationIndex].position;
            }
        }
        else
        {
            currentDestination = depressedTransform.position;
        }

        parent.transform.position = Vector3.MoveTowards
                                        (parent.transform.position, currentDestination, Time.deltaTime * speed);
    }
示例#3
0
    /* private void UpdateRayCastOrigins()
     * {
     *   Bounds bounds = physicalCollider.bounds;
     *   bounds.Expand(Collisions.SKIN_WIDTH * -2);
     *   rayCastOrigins.BottomLeft = new Vector2(bounds.min.x, bounds.min.y);
     *   rayCastOrigins.BottomRight = new Vector2(bounds.max.x, bounds.min.y);
     *   rayCastOrigins.TopLeft = new Vector2(bounds.min.x, bounds.max.y);
     *   rayCastOrigins.TopRight = new Vector2(bounds.max.x, bounds.max.y);
     * }
     * /* private void CalculateRaySpacing()
     * {
     *   Bounds bounds = physicalCollider.bounds;
     *   bounds.Expand(Collisions.SKIN_WIDTH * -2);
     *   horizontalRayCount = Mathf.Clamp(horizontalRayCount, 2, int.MaxValue);
     *   verticalRayCount = Mathf.Clamp(verticalRayCount, 2, int.MaxValue);
     *   horizontalRaySpacing = bounds.size.y / (horizontalRayCount - 1);
     *   verticalRaySpacing = bounds.size.x / (verticalRayCount - 1);
     * }*/
    private void Move(Vector3 velocity)
    {
        collisionInfo.Clear();
        collisionInfo.VelocityOld = velocity;
        Collisions.UpdateRayCastOrigins(physicalCollider, ref rayCastOrigins); //maybe we shouldnt do this every Move()
        Collisions.CalculateRaySpacing(physicalCollider, ref rayCastOrigins);  //maybe we shouldnt do this every Move()

        if (draggedObject != null)
        {
            draggedObjectPreviousPosition = draggedObject.transform.position;
            movedObjRelative = draggedObject.gameObject.transform.InverseTransformPoint(transform.position);
            Collisions.UpdateRayCastOrigins(draggedObject.Collider, ref draggedObject.RayCastOrigins);
            Collisions.CalculateRaySpacing(draggedObject.Collider, ref draggedObject.RayCastOrigins);
            if (velocity.x != 0)
            {
                DraggedHorizontalCollisions(ref velocity);
            }
            draggedObject.transform.Translate(new Vector3(velocity.x, 0, 0));
        }
        if (velocity.y < 0)
        {
            DescendSlope(ref velocity);
        }
        if (velocity.x != 0)
        {
            collisionObject = HorizontalCollisions(ref velocity);
            if (collisionObject != null)
            {
                if (collisionObject.GetComponent <Collectible>())
                {
                    collisionObject.GetComponent <Collectible>().Collect();
                }
            }
            ;
        }
        if (velocity.y != 0)
        {
            collisionObject = VerticalCollisions(ref velocity);
            if (collisionObject != null)
            {
                if (collisionObject.GetComponent <Collectible>())
                {
                    collisionObject.GetComponent <Collectible>().Collect();
                }
                else if (collisionObject.GetComponentInParent <MovingPlatform>() || collisionObject.GetComponent <AmplifiedMovingPlatform>())
                {
                    this.transform.parent = collisionObject.transform.parent;
                }
            }
            else
            {
                this.transform.parent = null;
            }
        }
        transform.Translate(velocity);
        if (draggedObject != null)
        {
            draggedObject.transform.position = draggedObjectPreviousPosition;//an ugly solution to an ugly problem...
            draggedObject.transform.Translate(new Vector3(velocity.x, velocity.y, 0));
        }
    }