測試我們需要的程式碼
一、使用keyboard控制人物移動
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ThirdContoller : MonoBehaviour
{
public float Speed = 3.0f;
public float RotateSpeed = 3.0f;
void Start()
{
}
void Update()
{
float hor = Input.GetAxis("Horizontal");
float ver = Input.GetAxis("Vertical");
transform.position += transform.forward * Time.deltaTime * ver * 3 * Speed;
transform.Rotate(transform.up * Time.deltaTime * hor * 90 * RotateSpeed);
}
}
原本使用的是wasd控制移動,但是發現如果這樣子的話人物移動會不流暢,而且人物面對的方向也會有有問題,於是改成這樣,ws控制前進後退,ad控制人物的朝向,這樣就可以讓人物平滑的移動了
沒有留言:
張貼留言