gpt4 book ai didi

c# - 分配动画后角色位置移动

转载 作者:太空宇宙 更新时间:2023-11-03 13:27:51 26 4
gpt4 key购买 nike

我的角色位置在分配动画后移动。

角色 GameObject 被分配了 AnimationRigidBodyCapsule Collider 和一个 C# Script 组件。

C#脚本(动画部分)如下:

public class MyCharacter : MonoBehaviour {
// Animations
public AnimationClip idleAnimation;
public AnimationClip slideAnimation;
public AnimationClip runAnimation;
public AnimationClip jumpPoseAnimation;
private Animation charAnimation;

enum CharacterState {
Idle = 0,
Running = 1,
Sliding = 2,
Jumping = 3,
}

private CharacterState charState;

void Start () {
charState = CharacterState.Running;
charAnimation = gameObject.GetComponent<Animation>();
if(!charAnimation) {
Debug.Log("No Animation Component.");
} else {
AnimationEvent syncRunEvent = new AnimationEvent();
syncRunEvent.time = runAnimation.length;
syncRunEvent.functionName = "SyncRunAnimation";
runAnimation.AddEvent(syncRunEvent);
}
}

void Update () {
// Animations
if(charAnimation) {
if(charState == CharacterState.Jumping) {
charAnimation.CrossFade(jumpPoseAnimation.name);
} else if(charState == CharacterState.Sliding) {
charAnimation.CrossFade(slideAnimation.name);
} else {
charAnimation.CrossFade(runAnimation.name);
}
}
}

void SyncRunAnimation() {
Debug.Log("Sync Run");
transform.position += new Vector3(0, 3, 0);
}
}

在分配动画之前,角色站在地面上 (0, 0.6, 0) 的位置。分配后,角色潜入地面,卡住;位置更改为(0, -0.75, -0.55),即导入动画的位置。如何控制动画位置?

注意:我尝试使用 SyncEvent 向上移动(增加 Y 轴),但它根本没有效果。


这仅在 Animation 设置为 Legacy 时发生。如果我将动画设置为 Generic,它没有问题,但控制台会出现错误:

The AnimationClip 'run' used by the Animation component 'MyCharacter' must be marked as Legacy.

动画无法播放。我怎样才能使它与通用动画一起工作/使用传统动画正确定位?

最佳答案

我发现 FBX 动画的位置关键帧会影响位置。删除动画面板中的属性后,问题就消失了。

Remove this Properties

但是,关键帧有时会重新出现。

关于c# - 分配动画后角色位置移动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21747184/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com