【发布时间】:2021-08-15 04:03:33
【问题描述】:
这是混合树的屏幕截图。顶部的第一个动画是空闲的,在左侧底部有一个 Forward,我还添加了一个 Forward 参数。这个前锋控制玩家的移动速度。
通过将此脚本附加到播放器,我正在控制 Forward 参数并减慢播放器的移动速度。
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
public class PlayerSpaceshipAreaColliding : MonoBehaviour
{
public float rotationSpeed =250;
public float movingSpeed;
public float secondsToRotate;
public GameObject uiSceneText;
public TextMeshProUGUI textMeshProUGUI;
private float timeElapsed = 0;
private float lerpDuration = 3;
private float startValue = 1;
private float endValue = 0;
private float valueToLerp = 0;
private Animator playerAnimator;
private bool exitSpaceShipSurroundingArea = false;
private bool slowd = true;
private bool startRotatingBack = false;
private bool displayText = true;
private float desiredRot;
public float damping = 10;
private Rigidbody playerRigidbody;
// Start is called before the first frame update
void Start()
{
playerAnimator = GetComponent<Animator>();
playerRigidbody = GetComponent<Rigidbody>();
desiredRot = transform.eulerAngles.y;
}
// Update is called once per frame
void Update()
{
if (exitSpaceShipSurroundingArea)
{
if (slowd)
SlowDown();
if (playerAnimator.GetFloat("Forward") == 0)
{
slowd = false;
LockController.PlayerLockState(false);
if (displayText)
{
uiSceneText.SetActive(true);
if (textMeshProUGUI.text != "")
textMeshProUGUI.text = "";
textMeshProUGUI.text = "I can see something very far in the distance, but it's too long to walk by foot.";
StartCoroutine(UITextWait());
displayText = false;
}
}
}
}
IEnumerator UITextWait()
{
yield return new WaitForSeconds(5f);
textMeshProUGUI.text = "";
uiSceneText.SetActive(false);
startRotatingBack = true;
}
private void OnTriggerEnter(Collider other)
{
if (other.name == "CrashLandedShipUpDown")
{
exitSpaceShipSurroundingArea = false;
Debug.Log("Entered Spaceship Area !");
}
}
private void OnTriggerExit(Collider other)
{
if (other.name == "CrashLandedShipUpDown")
{
exitSpaceShipSurroundingArea = true;
Debug.Log("Exited Spaceship Area !");
}
}
private void SlowDown()
{
if (timeElapsed < lerpDuration)
{
valueToLerp = Mathf.Lerp(startValue, endValue, timeElapsed / lerpDuration);
playerAnimator.SetFloat("Forward", valueToLerp);
timeElapsed += Time.deltaTime;
}
playerAnimator.SetFloat("Forward", valueToLerp);
valueToLerp = 0;
}
}
问题是当 Forward 的值变为 0 并且玩家停止跳到混合树中的空闲动画并且不平滑地切换到它时。
我用红色圆圈标记的检查器中的空闲动画(更改动画速度)的值与其余部分一样为 1 但因为它有点跳到空闲我将其更改为 0.5 但现在整个空闲动画是播放太慢,就像慢动作一样。
我不知道为什么它从减速到空闲的变化看起来像是在切割跳跃而不是平滑地切换到空闲动画?
【问题讨论】:
-
我找到了解决方案。相反,在脚本 ThirdPersonUserControl 中,像在 LockController.PlayerLockState(false); 行中那样禁用它我刚刚向 ThirdPersonUserControl 脚本添加了一个公共静态布尔值,当它为真时,它不允许使用 FixedUpdate 中的输入。现在效果很好。
-
如果您认为您找到了解决此类问题的方法,请不要发表评论,但请正确回答您的问题,以便 a)人们可以看到这已经有了答案,并且 b)有类似问题的人可以找到更好的解决方案