Animation 统一性:使用InputManager(侧滚动器)时更改方向字符面
我正在创建一个简单的侧边滚动条,有几个人使用Unity,我绝对是个初学者。使用的角色是3D的,向前跑得很好,但向后跑时,他仍然面朝前。我在InputManager中设置了控件,所以按A键向后移动,按D键向前移动,但我不确定该怎么做,他会面对自己的移动 任何帮助都将不胜感激,如果你需要更多的信息,除了下面的代码我有运动让我知道,这是根据另一个帖子我发现Animation 统一性:使用InputManager(侧滚动器)时更改方向字符面,animation,unity3d,unityscript,side-scroller,Animation,Unity3d,Unityscript,Side Scroller,我正在创建一个简单的侧边滚动条,有几个人使用Unity,我绝对是个初学者。使用的角色是3D的,向前跑得很好,但向后跑时,他仍然面朝前。我在InputManager中设置了控件,所以按A键向后移动,按D键向前移动,但我不确定该怎么做,他会面对自己的移动 任何帮助都将不胜感激,如果你需要更多的信息,除了下面的代码我有运动让我知道,这是根据另一个帖子我发现 var speed : float = 6.0; var jumpSpeed : float = 6.0; var gravity : float
var speed : float = 6.0;
var jumpSpeed : float = 6.0;
var gravity : float = 12.0;
//This variable is now inheriting the Vector3 info (X,Y,Z) and setting them to 0.
private var moveDirection : Vector3 = Vector3.zero;
function MoveAndJump() {
var controller : CharacterController = GetComponent(CharacterController);
if(controller.isGrounded) {
//moveDirection is inheriting Vector3 info. This now sets the X and Z coords to receive the input set to "Horizontal" and "Vertical"
moveDirection = Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical")); //Allows player Input
moveDirection = transform.TransformDirection(moveDirection); //How to move
moveDirection *= speed; //How fast to move
if(Input.GetButtonDown("Jump")) {
animation.Play("Jump");
moveDirection.y = jumpSpeed;
}
}
//Apply gravity
moveDirection.y -= gravity * Time.deltaTime;
//This moves the controller
controller.Move(moveDirection * Time.deltaTime);
if(Input.GetButton("Fire1")){
animation.Play("Attack");
}
if(Input.GetButton("Vertical")){
animation.Play("Run");
}
}
function Update() {
MoveAndJump();
}
值得一提的是,我遇到的另一个问题涉及到两个不同的动画能够同时工作,比如奔跑和攻击。我想我在这里的时候应该提一下,如果有人知道怎么做的话。再次感谢您抽出时间 我最终根据我偶然发现的另一个代码解决了这个问题,然后调用了Update()中的函数:
您是否尝试过修改transform.localRotation=新向量(0,180,0)?Hm我回来了:“无法将‘UnityEngine.Vector3’转换为‘UnityEngine.Quaternion’”(我假设你指的是Vector3)。我想我可能只是使用GetKey而不是InputManagerAha,这是我的错误。我已经纠正了它,如下面的答案所示。
var speed : float;
var jumpSpeed : float;
var gravity : float;
private var moveDirection : Vector3 = Vector3.zero;
function MoveJumpAttack() {
var controller : CharacterController = GetComponent(CharacterController);
if (controller.isGrounded) {
moveDirection = Vector3(Input.GetAxis("Horizontal"), 0, 0);
moveDirection *= speed;
if (moveDirection.sqrMagnitude > 0.01)
transform.rotation = Quaternion.Slerp (transform.rotation, Quaternion.LookRotation (moveDirection), 90);
}
moveDirection.y -= gravity * Time.deltaTime;
controller.Move(moveDirection * Time.deltaTime);
}