Exemple #1
0
    void LateUpdate()
    {
        Vector3 delta = transform.position - prevPosition;

        prevPosition = transform.position;

        foreach (Transform t in stuckObjects)
        {
            PawnAABB3D pawn = t.GetComponent <PawnAABB3D>();
            if (pawn)
            {
                PawnAABB3D.CollisionResults results = pawn.Move(delta);

                // TODO: move into PAWNAABB3D class?

                // convert local distance into world space
                Vector3 worldSpaceDistance = t.TransformVector(results.distanceLocal);
                // add to player position
                t.transform.position += worldSpaceDistance;
            }
            else
            {
                t.transform.Translate(delta);
            }
        }
    }
Exemple #2
0
    /// <summary>
    /// Perform collision detection by calling the PawnAABB's collision detection methods.
    /// The results of collision detection are then applied.
    /// </summary>
    private void DoCollisions()
    {
        PawnAABB3D.CollisionResults results = pawn.Move(velocity * Time.deltaTime);
        if (results.hitTop || results.hitBottom)
        {
            velocity.y = 0;
        }
        if (results.hitLeft || results.hitRight)
        {
            velocity.x = 0;
        }
        isGrounded = results.hitBottom || results.ascendSlope;

        float distanceFromPlayer = Vector2.Distance(Player.PlayerController.main.transform.position, transform.position);

        if (isGrounded)
        {
            if (distanceFromPlayer < MAX_DISTANCE)
            {
                isBurrowing    = true;
                preBurrowPoint = transform.position;
            }
        }
        else if (distanceFromPlayer < 1)
        {
            SetHugging();
        }

        if (!isHugging)
        {
            transform.position += results.distanceLocal;
        }
    }