Ejemplo n.º 1
0
    private void MovePlayer()
    {
        //with vertical input move player toward or away from targeted player
        Vector3 slopeVector   = SlopeCheck();
        float   moveIntensity = Vector2.Distance(Vector2.zero, new Vector2(horizontalInput, verticalInput));

        dirToTarget   = targetedEnemy.transform.position - transform.position;
        dirToTarget.y = 0;
        dirToTarget.Normalize();
        float forward = dirToTarget.z * moveSpeed * verticalInput;

        //with horizontal input move player left or right in relation to the forward vector
        Vector3 leftFromTarget = Vector3.Cross(dirToTarget, Vector3.up).normalized;

        Vector3 forwardVector = (transform.forward + dirToTarget) * moveSpeed * verticalInput * Time.fixedDeltaTime;
        Vector3 leftVector    = (transform.right + leftFromTarget * -1) * moveSpeed * horizontalInput * Time.fixedDeltaTime;

        playerRb.velocity = forwardVector + leftVector;

        Debug.DrawRay(transform.position, dirToTarget, Color.green, .2f);
        Debug.DrawRay(transform.position, dirToTarget * -1, Color.red, .2f);
        Debug.DrawRay(transform.position, leftFromTarget, Color.blue, .2f);
        Debug.DrawRay(transform.position, leftFromTarget * -1, Color.yellow, .2f);

        verticalVector = dirToTarget + slopeVector;
        playerAnimationController.HandlePlayerZTargetingBlend(verticalInput, horizontalInput);
    }