예제 #1
0
 public void OnLanded()
 {
     OnLandedEvent?.Invoke();
     foreach (var handler in handlers)
     {
         handler.OnLanded();
     }
 }
예제 #2
0
    /// <summary>
    /// Resolves the collisions moving horizontally and vertically, then with the calculated values translates to velocity vector.
    /// </summary>
    /// <param name="deltaMovement"> The amount of movement to be applied </param>
    public void Move(Vector2 deltaMovement, bool standingOnPlatform = false)
    {
        UpdateRaycastOrigins();

        if (!collisionInfo.wasGroundedLastFrame && collisionInfo.below)
        {
            OnLandedEvent?.Invoke();
            // Debug.Log("Landed!");
        }

        if (collisionInfo.wasGroundedLastFrame && !collisionInfo.below && deltaMovement.y < 0)
        {
            OnFellEvent?.Invoke();
            // Debug.Log("Fell!");
        }

        collisionInfo.Reset();

        // Only go down a slope if we are not ascending in the y direction.
        if (deltaMovement.y < 0)
        {
            DescendSlope(ref deltaMovement);
        }


        if (deltaMovement.x != 0)
        {
            HorizontalCollisionRes(ref deltaMovement);
        }

        //if(velocity.y != 0)
        VerticalCollisionRes(ref deltaMovement);

        ignoreSlopeTime -= Time.deltaTime;

        ignoreOneWayPlatformThisFrame = false;

        objectTransform.Translate(deltaMovement);

        if (standingOnPlatform)
        {
            collisionInfo.below = true;
        }
    }