public float movespeed = 0.0f;
private float x;
private float y;
private float z;
private CharacterController controller;
private Vector3 moveDirection;
void Update () {
Vector3 pos = GameObject.FindWithTag("Player").transform.position;
x = pos.x;
y = pos.y;
z = pos.z;
moveDirection = Vector3.zero;
if(Input.GetKey(KeyCode.A))
transform.position = new Vector3(-1.3f, y, z);
else if(Input.GetKey(KeyCode.D))
transform.position = new Vector3(1.3f, y, z);
//moveDirection.x = Input.GetAxis("Horizontal") * movespeed;
moveDirection.z = movespeed;
controller.Move (moveDirection * Time.deltaTime);
}
我想让我的播放器在x轴的两个点之间移动,即-1.3和1.3,并且使用上面的代码,我能够实现,但它只是传送(我知道代码是如何制作的)。我希望过渡顺利。任何想法我怎样才能实现这一目标?
答案 0 :(得分:0)
感谢上面的评论,我能够让它工作:) 这里正确的做法是使用SLerp。我这样用它: -
transform.position = Vector3.Slerp (pos, newPos, movespeed);
首先我使用pos的值复制newPos,然后在newPos中仅更改x轴值(以获得我想要的结果)。