2024-10-21 10:08:49 +08:00
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD>Խ<EFBFBD><D4BD><EFBFBD><EFBFBD><EFBFBD>ø<EFBFBD><C3B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
public class Skill_Jump : MonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
private CharacterAin CharacterAin; // <20><><EFBFBD>ڿ<EFBFBD><DABF>Ʒ<EFBFBD>Խ<EFBFBD><D4BD><EFBFBD><EFBFBD>
|
|
|
|
|
public float vaultDistance = 2f; // <20><>ɫ<EFBFBD><C9AB><EFBFBD>Է<EFBFBD>Խ<EFBFBD><D4BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
public float vaultHeight = 2f; // <20><>ɫ<EFBFBD><C9AB><EFBFBD>Է<EFBFBD>Խ<EFBFBD><D4BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߶<EFBFBD>
|
|
|
|
|
public LayerMask vaultLayerMask; // <20><><EFBFBD>ڼ<EFBFBD><DABC><EFBFBD><EFBFBD>ɷ<EFBFBD>Խ<EFBFBD><D4BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> Layer
|
|
|
|
|
public float vaultForwardDistance = 0.5f; // <20>ɵ<EFBFBD><C9B5><EFBFBD><EFBFBD>ķ<EFBFBD>Խǰ<D4BD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
public float vaultUpwardHeight = 1.0f; // <20>ɵ<EFBFBD><C9B5><EFBFBD><EFBFBD>ķ<EFBFBD>Խ<EFBFBD>߶<EFBFBD>
|
|
|
|
|
|
|
|
|
|
private bool isVaulting = false; // <20><>־<EFBFBD><D6BE>ɫ<EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD>ڷ<EFBFBD>Խ
|
|
|
|
|
private Collider characterCollider; // <20><>ɫ<EFBFBD><C9AB><EFBFBD><EFBFBD>ײ<EFBFBD><D7B2>
|
2024-12-02 15:09:22 +08:00
|
|
|
|
public Rigidbody characterRigidbody; // <20><>ɫ<EFBFBD>ĸ<EFBFBD><C4B8><EFBFBD>
|
2024-10-21 10:08:49 +08:00
|
|
|
|
|
|
|
|
|
private void Start()
|
|
|
|
|
{
|
|
|
|
|
CharacterAin = transform.GetComponent<CharacterAin>();
|
|
|
|
|
characterCollider = GetComponent<Collider>();
|
|
|
|
|
characterRigidbody = GetComponent<Rigidbody>();
|
|
|
|
|
}
|
|
|
|
|
void Update()
|
|
|
|
|
{
|
|
|
|
|
if (Input.GetKeyDown(KeyCode.Space) && !isVaulting)
|
|
|
|
|
{
|
|
|
|
|
Debug.Log("<22><><EFBFBD>·<EFBFBD>Խ");
|
|
|
|
|
CheckForVault();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD>Է<EFBFBD>Խ
|
|
|
|
|
private void CheckForVault()
|
|
|
|
|
{
|
|
|
|
|
Debug.Log("<22><><EFBFBD>ڼ<EFBFBD><DABC><EFBFBD>");
|
|
|
|
|
RaycastHit hit;
|
|
|
|
|
|
|
|
|
|
// <20>ӽ<EFBFBD>ɫǰ<C9AB><C7B0><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD>ߣ<EFBFBD><DFA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD>ϰ<EFBFBD><CFB0><EFBFBD>
|
|
|
|
|
if (Physics.Raycast(transform.position, transform.forward, out hit, vaultDistance, vaultLayerMask))
|
|
|
|
|
{
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E2B5BD><EFBFBD>ϰ<EFBFBD><CFB0><EFBFBD><EFBFBD>߶<EFBFBD><DFB6>ʺϷ<CABA>Խ
|
|
|
|
|
if (hit.collider.bounds.size.y <= vaultHeight)
|
|
|
|
|
{
|
|
|
|
|
Debug.Log("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Է<EFBFBD>Խ");
|
|
|
|
|
StartVault(hit.point);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// <20><>ʼ<EFBFBD><CABC>Խ<EFBFBD><D4BD><EFBFBD><EFBFBD>
|
|
|
|
|
private void StartVault(Vector3 hitPoint)
|
|
|
|
|
{
|
|
|
|
|
Debug.Log("<22><>Խ");
|
|
|
|
|
isVaulting = true;
|
|
|
|
|
CharacterAin.SetSkillAin(CharacterSkill.jump);
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ײ<EFBFBD><D7B2><EFBFBD><EFBFBD><CDB8>壬<EFBFBD><E5A3AC>ֹ<EFBFBD><D6B9>Խʱ<D4BD>ܵ<EFBFBD><DCB5><EFBFBD><EFBFBD><EFBFBD>Ӱ<EFBFBD><D3B0>
|
|
|
|
|
characterCollider.enabled = false;
|
|
|
|
|
characterRigidbody.isKinematic = true;
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD>ý<EFBFBD>ɫ<EFBFBD><C9AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƶ<EFBFBD><C6B6><EFBFBD><EFBFBD><EFBFBD>ֹ<EFBFBD><D6B9>Խʱ<D4BD>ƶ<EFBFBD><C6B6><EFBFBD>Ӱ<EFBFBD><D3B0>
|
|
|
|
|
GetComponent<CharacterControl>().enabled = false;
|
|
|
|
|
|
|
|
|
|
// <20>ý<EFBFBD>ɫ<EFBFBD>ƶ<EFBFBD><C6B6><EFBFBD><EFBFBD><EFBFBD>Խ<EFBFBD><D4BD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>
|
|
|
|
|
StartCoroutine(VaultMovement(hitPoint));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD>ƽ<EFBFBD>ɫ<EFBFBD><C9AB>Խ<EFBFBD><D4BD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD><D0B5>ƶ<EFBFBD>
|
|
|
|
|
private IEnumerator VaultMovement(Vector3 hitPoint)
|
|
|
|
|
{
|
|
|
|
|
// <20><><EFBFBD><EFBFBD> hitPoint <20><> Y <20>ᣬȷ<E1A3AC><C8B7><EFBFBD><EFBFBD>ɫƽ<C9AB><C6BD><EFBFBD>ƶ<EFBFBD>
|
|
|
|
|
Vector3 horizontalHitPoint = new Vector3(hitPoint.x, transform.position.y, hitPoint.z);
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Խ<EFBFBD><D4BD>λ<EFBFBD>ƺ߶<CDB8>
|
|
|
|
|
Vector3 targetPosition = horizontalHitPoint + transform.forward * vaultForwardDistance;
|
|
|
|
|
targetPosition.y += vaultUpwardHeight; // <20><>Ŀ<EFBFBD><C4BF>λ<EFBFBD><CEBB><EFBFBD>ϼ<EFBFBD><CFBC>ϸ߶ȵ<DFB6><C8B5><EFBFBD>
|
|
|
|
|
|
|
|
|
|
float vaultTime = 1.0f; // <20><>Խ<EFBFBD><D4BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
|
|
|
|
|
float elapsedTime = 0f;
|
|
|
|
|
|
|
|
|
|
Vector3 startPosition = transform.position;
|
|
|
|
|
|
|
|
|
|
while (elapsedTime < vaultTime)
|
|
|
|
|
{
|
|
|
|
|
transform.position = Vector3.Lerp(startPosition, targetPosition, elapsedTime / vaultTime); // ƽ<><C6BD><EFBFBD>ƶ<EFBFBD><C6B6><EFBFBD>ɫ
|
|
|
|
|
elapsedTime += Time.deltaTime;
|
|
|
|
|
yield return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
transform.position = targetPosition; // ȷ<><C8B7><EFBFBD><EFBFBD>ɫ<EFBFBD><C9AB><EFBFBD><EFBFBD>Ŀ<EFBFBD><C4BF>λ<EFBFBD><CEBB>
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƺ<EFBFBD><C6BA><EFBFBD>ײ<EFBFBD><D7B2>
|
|
|
|
|
characterRigidbody.isKinematic = false;
|
|
|
|
|
characterCollider.enabled = true;
|
|
|
|
|
GetComponent<CharacterControl>().enabled = true;
|
|
|
|
|
|
|
|
|
|
// ȷ<><C8B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӱ<EFBFBD><D3B0>
|
|
|
|
|
characterRigidbody.velocity = Vector3.zero; // <20><><EFBFBD><EFBFBD><EFBFBD>κβ<CEBA><CEB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ٶ<EFBFBD>
|
|
|
|
|
characterRigidbody.AddForce(Vector3.down * 9.81f, ForceMode.VelocityChange); // ʩ<><CAA9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
|
|
|
|
CharacterAin.SetSkillAin(CharacterSkill.NoSkill);
|
|
|
|
|
isVaulting = false; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Խ<EFBFBD><D4BD><EFBFBD><EFBFBD>
|
|
|
|
|
Debug.Log("<22><>Խ<EFBFBD><D4BD><EFBFBD><EFBFBD>");
|
|
|
|
|
}
|
|
|
|
|
}
|