- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的问题是,我在Unity3D的第三人称 Controller 中设置的自定义行走动画没有显示。
动画是从具有 model@walk.fbx 结构的 FBX 文件导入的。我知道动画有效,因为如果我将它用作它显示的空闲动画。另一方面,这似乎也不是 Controller 脚本的问题,因为它与原型(prototype)角色配合得很好。
似乎正在播放的动画是在动画组件中选择的动画(已选择“自动播放”)。任何从第三人称 Controller 更改动画的尝试都适用于原型(prototype)角色,但不适用于我的角色。
我没有也不想要运行和跳跃动画。对于原型(prototype)角色,我为每个角色设置了行走动画,没有产生任何不利影响。 Controller 不会以这种方式关闭动画,因为控制台中没有来自第三人称 Controller 脚本的日志条目。与 CrossFade 调用相关的线路正在被调用。
有什么线索可以告诉我下一步可以去哪里吗?更有可能是 Controller 问题还是动画问题?完全是别的东西吗?
更新:下面是我的 Controller 的代码。当我使用 Unity 提供的建筑 worker 示例模型时,效果很好。带有 _animation.CrossFade
的行将在预期时间被调用。使用 Play
或 Blend
没有帮助。控制台中没有记录任何错误。
对于我们的自定义动画,它不起作用。我现在怀疑问题出在模型上。不幸的是,我无权分享该模型的示例。我已向动画师询问有关他如何创建 FBX 导出的更多详细信息。为了使模型在 Unity 中工作,他需要使用任何特定设置吗?但奇怪的是,如果我将它们独立地添加到场景中,动画确实可以工作。
// Require a character controller to be attached to the same game object
@script RequireComponent(CharacterController)
public var idleAnimation : AnimationClip;
public var walkAnimation : AnimationClip;
public var walkMaxAnimationSpeed : float = 0.75;
private var _animation : Animation;
enum CharacterState {
Idle = 0,
Walking = 1,
}
private var _characterState : CharacterState;
// The speed when walking
var walkSpeed = 2.0;
var speedSmoothing = 10.0;
var rotateSpeed = 500.0;
var targetPrecision = 5;
var targetMaxDistance = 200;
// The camera doesnt start following the target immediately but waits for a split second to avoid too much waving around.
private var lockCameraTimer = 0.0;
// The current move direction in x-z
private var moveDirection = Vector3.zero;
// The current x-z move speed
private var moveSpeed = 0.0;
// The last collision flags returned from controller.Move
private var collisionFlags : CollisionFlags;
// Are we moving backwards (This locks the camera to not do a 180 degree spin)
private var movingBack = false;
// Is the user pressing any keys?
private var isMoving = false;
private var isControllable = true;
private var isTargetting : boolean = false;
private var targetPoint : Vector3 = Vector3.zero;
function Awake () {
moveDirection = transform.TransformDirection(Vector3.forward);
_animation = GetComponent(Animation);
if(!_animation)
Debug.Log("The character you would like to control doesn't have animations. Moving her might look weird.");
if(!idleAnimation) {
_animation = null;
Debug.Log("No idle animation found. Turning off animations.");
}
//_animation[idleAnimation.name] = idleAnimation;
if(!walkAnimation) {
_animation = null;
Debug.Log("No walk animation found. Turning off animations.");
}
//_animation[walkAnimation.name] = walkAnimation;
}
function UpdateSmoothedMovementDirection () {
var cameraTransform = Camera.main.transform;
// Forward vector relative to the camera along the x-z plane
var forward = cameraTransform.TransformDirection(Vector3.forward);
forward.y = 0;
forward = forward.normalized;
// Right vector relative to the camera
// Always orthogonal to the forward vector
var right = Vector3(forward.z, 0, -forward.x);
var v = Input.GetAxisRaw("Vertical");
var h = Input.GetAxisRaw("Horizontal");
// Are we moving backwards or looking backwards
if (v < -0.2)
movingBack = true;
else
movingBack = false;
var wasMoving = isMoving;
isMoving = Mathf.Abs (h) > 0.1 || Mathf.Abs (v) > 0.1;
// Target direction relative to the camera
var targetDirection = h * right + v * forward;
// Lock camera for short period when transitioning moving & standing still
lockCameraTimer += Time.deltaTime;
if (isMoving != wasMoving)
lockCameraTimer = 0.0;
// We store speed and direction seperately,
// so that when the character stands still we still have a valid forward direction
// moveDirection is always normalized, and we only update it if there is user input.
if (targetDirection != Vector3.zero) {
// If we are really slow, just snap to the target direction
if (moveSpeed < walkSpeed * 0.9) {
moveDirection = targetDirection.normalized;
}
// Otherwise smoothly turn towards it
else {
moveDirection = Vector3.RotateTowards(moveDirection, targetDirection, rotateSpeed * Mathf.Deg2Rad * Time.deltaTime, 1000);
moveDirection = moveDirection.normalized;
}
}
// Smooth the speed based on the current target direction
var curSmooth = speedSmoothing * Time.deltaTime;
// Choose target speed
//* We want to support analog input but make sure you cant walk faster diagonally than just forward or sideways
var targetSpeed = Mathf.Min(targetDirection.magnitude, 1.0);
_characterState = CharacterState.Idle;
// Pick speed modifier
targetSpeed *= walkSpeed;
_characterState = CharacterState.Walking;
moveSpeed = Mathf.Lerp(moveSpeed, targetSpeed, curSmooth);
}
function UpdateTargettedMovementDirection () {
var cameraTransform = Camera.main.transform;
var wasMoving = isMoving;
isMoving = true;//Mathf.Abs (h) > 0.1 || Mathf.Abs (v) > 0.1;
// Target direction relative to the camera
// var targetDirection = h * right + v * forward;
var targetDirection = Vector3.zero;
targetDirection.x = targetPoint.x - transform.position.x;
targetDirection.z = targetPoint.z - transform.position.z;
targetDirection = targetDirection.normalized;
//Debug.Log("Target direction is " + targetDirection);
// Lock camera for short period when transitioning moving & standing still
lockCameraTimer += Time.deltaTime;
if (isMoving != wasMoving)
lockCameraTimer = 0.0;
// We store speed and direction seperately,
// so that when the character stands still we still have a valid forward direction
// moveDirection is always normalized, and we only update it if there is user input.
if (targetDirection != Vector3.zero) {
// If we are really slow, just snap to the target direction
if (moveSpeed < walkSpeed * 0.9) {
moveDirection = targetDirection.normalized;
}
// Otherwise smoothly turn towards it
else {
moveDirection = Vector3.RotateTowards(moveDirection, targetDirection, rotateSpeed * Mathf.Deg2Rad * Time.deltaTime, 1000);
moveDirection = moveDirection.normalized;
}
}
// Smooth the speed based on the current target direction
var curSmooth = speedSmoothing * Time.deltaTime;
// Choose target speed
//* We want to support analog input but make sure you cant walk faster diagonally than just forward or sideways
var targetSpeed = Mathf.Min(targetDirection.magnitude, 1.0);
_characterState = CharacterState.Idle;
// Pick speed modifier
targetSpeed *= walkSpeed;
_characterState = CharacterState.Walking;
moveSpeed = Mathf.Lerp(moveSpeed, targetSpeed, curSmooth);
}
function Update() {
if (!isControllable) {
// kill all inputs if not controllable.
Input.ResetInputAxes();
}
var distance : float = 0;
if (Input.GetMouseButtonUp(0)) {
if (isTargetting) {
isTargetting = false;
// Debug.Log("Stopped moving");
FaceCamera();
} else {
var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
var layerMask = 1 << 8; // Terrain is layer 8
var hit : RaycastHit;
Physics.Raycast(Camera.main.transform.position, ray.direction, hit, 1000, layerMask);
distance = Vector3.Distance(transform.position, hit.point);
if (distance <= targetMaxDistance && hit.point != Vector3.zero) {
targetPoint = hit.point;
isTargetting = true;
// Debug.Log("Mouse up at hit " + hit.point + " at distance " + distance);
} else {
isTargetting = false;
// Debug.Log("Ignored mouse up at hit " + hit.point + " at distance " + distance);
}
}
}
if (isTargetting) {
// Debug.Log("Moving to " + targetPoint);
distance = Vector3.Distance(transform.position, targetPoint);
if (distance < targetPrecision) {
// Debug.Log("Reached point " + targetPoint + " at distance " + distance);
isTargetting = false;
FaceCamera();
} else {
UpdateTargettedMovementDirection();
}
} else {
UpdateSmoothedMovementDirection();
}
// Calculate actual motion
var movement = moveDirection * moveSpeed;
movement *= Time.deltaTime;
// Move the controller
var controller : CharacterController = GetComponent(CharacterController);
collisionFlags = controller.Move(movement);
// ANIMATION sector
if (_animation) {
if (controller.velocity.sqrMagnitude < 0.1) {
_animation.CrossFade(idleAnimation.name);
} else {
//_animation[walkAnimation.name].speed = Mathf.Clamp(controller.velocity.magnitude, 0.0, walkMaxAnimationSpeed);
_animation.CrossFade(walkAnimation.name);
}
} else {
Debug.Log("Animation is null!");
}
// ANIMATION sector
// Set rotation to the move direction
transform.rotation = Quaternion.LookRotation(moveDirection);
}
function OnControllerColliderHit (hit : ControllerColliderHit ) {
// Debug.DrawRay(hit.point, hit.normal);
if (hit.moveDirection.y > 0.01)
return;
}
function GetSpeed () {
return moveSpeed;
}
function GetDirection () {
return moveDirection;
}
function IsMovingBackwards () {
return movingBack;
}
function GetLockCameraTimer () {
return lockCameraTimer;
}
function IsMoving () : boolean {
return Mathf.Abs(Input.GetAxisRaw("Vertical")) + Mathf.Abs(Input.GetAxisRaw("Horizontal")) > 0.5;
}
function Reset () {
gameObject.tag = "Player";
}
function FaceCamera() {
var cameraTransform = Camera.main.transform;
// Forward vector relative to the camera along the x-z plane
var forward = cameraTransform.TransformDirection(Vector3.forward);
forward.y = 0;
forward = forward.normalized;
moveDirection = -forward;
}
更新 2: 用于创建动画的设置位于这些屏幕截图中。它们正确吗?
最佳答案
(还:-)没有答案,但我需要更多的空间和图像。
自 Unity3d 3.5 以来,处理基于animation@model.fbx 表示法的导入的方式已经改变,并且有些人报告了问题(例如 BIG Unity 3.5.0f1 problem with Skinned Rig - Major FAIL )。当第二个根骨骼开始播放时就会出现问题,但我可以通过将动画拖动到模型文件预制件来解决这个问题(我的大部分动画都包含在模型中,其余的 2 个动画也没什么大问题)。
为了确保我正确理解您在评论部分的回答,您有这样的内容:
这意味着:
假设这没问题,还有一些建议:
Debug.Log ("Walk: "+ player.animation.IsPlaying ("Walk")); 时会得到什么输出
[更新]
让我们看看导入设置。你有分割动画检查过,开始处是否可能输入了错误的值以及结束就像1-1?
关于unity-game-engine - Unity3D 第三人称 Controller 和动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10394573/
我正在制作一个简单的游戏,其中敌人在屏幕上四处移动,我们需要射击他们。我想模块化我的代码,所以我想用一个函数替换游戏循环逻辑。但是一旦我这样做,就会有一个下降以 fps 为单位。在while循环中调用
我使用的是标准匹配用户界面和两台 iPad iOS6。问题是当我在第一台设备中创建新的匹配项时,第二台设备应该在我查看匹配用户界面时看到现有的匹配项,但事实并非如此。我确定我的代码是正确的。这是方法:
在 The Practical Guide to Defect Prevention ,作者提到在软件开发中提高生产力的一种创造性方法是实现“生产力游戏”,员工以类似于在 Stack Overflow
我无法让游戏中心与我的应用一起工作。 每当我尝试对用户进行身份验证时,它都会返回以下错误: "The requested operation could not be completed becaus
我是 Game Maker 的新手。我已经创建了一个基于物理的小游戏的机制,并且我使用了 YoYo Games 教程中概述的方法来创建复杂的物理对象 (http://www.yoyogames.com
我正在编写一个 GML 脚本,想知道如何使消息出现在下一行: 例如。 show_message("Hello" + *something* + "World") 输出: Hello World 最佳答
关于这个已经有几个问题,但我按照他们的步骤解决了它,但它似乎对我不起作用。这是我所做的: 1.我仔细检查了 xcode 项目中的包标识符是否与供应门户上的供应配置文件完全相同(它还表示已启用 Game
GameKit 是否允许您以编程方式邀请特定的 Game Center friend 参加比赛,即不提供 GC ViewController?以下 handleInviteFromGameCenter
我正在 Game Maker: Studio 1.4 中构建客户端/服务器应用程序,需要运行游戏的两个实例进行测试。不幸的是,IDE 的运行/调试按钮在启动第一个副本后会自行禁用。有没有办法配置 ID
游戏已启动,我收到了用户的状态,一切就绪。我正在尝试构建一个问答游戏。我正在从远程服务器获取所有信息,其中包括基于问题的图像 Assets 。我可以获取远程数据,但无法显示图像。看来 facebook
我正在努力度过让 Game Center 集成发挥作用的第一阶段。我已经走到这一步了: 我创建了一个干净的新应用,在应用委托(delegate)中添加了 GameKit header 和基本的 aut
DragonRuby Game Toolkit 中好像没有按钮的概念。如何创建按钮等 UI 组件? 最佳答案 按钮(和任何其他 UI 组件)可以解构为 primitives: 按钮有一个点击空间(通常
我正在使用 DragonRuby Game Toolkit 构建游戏。 如何检测一个对象(例如 Sprite)是否与另一个 Sprite 发生碰撞? 这是放置在屏幕上的两个 Sprite 。关于如何检
我已经在我的应用中成功实现了 Game Center 排行榜,并使用 iOS 模拟器进行了测试。将新版本提交到 iTunes Connect 后,沙盒分数会转换到真正的 Game Center 吗?我
我读到 Unity 在渲染清晰文本时出现问题,我尝试了几种不同的修复方法:在导入的字体上设置较大的字体大小,并将字符设置更改为 unicode,使文本大小变大,然后缩放它向下,将过滤模式设置为指向像素
假设角色在游戏中跳跃需要一整秒,如果 FPS 为 10fps、30fps、100fps 等,游戏开发人员如何将跳跃时间保持在 1 秒? - 如果你明白我的意思,你会如何阻止游戏的 fps 基本上影响游
我一直在询问有关我的 Libgdx 游戏 Google Play 游戏服务配置错误的问题。到目前为止,我已经解决了登录错误,但现在我被困在解锁成就上。所以我发布我的代码可能有人可以帮助我。 这是我在
我正在将我的 Android 应用程序更新到最新的 Facebook SDK (4.0.0)。当我创建 GameRequestDialog 时,它向我显示此消息:“游戏请求仅适用于游戏”,而不是向我的
我创建了 GameOver.sks 和 GameOver.swift。如何在默认的 sprite-kit 项目中连接它们,例如 GameSense.sks 和 GameSense.swift? 最佳答
当前收到一个错误,指出无法找到我的 bean 中的 bankOffer 属性。 它来 self 的 game.jsp 文件,如下所示:
我是一名优秀的程序员,十分优秀!