第三人称移动

来源:互联网 发布:道衍和尚 知乎 编辑:程序博客网 时间:2024/04/27 19:22

第三人称控制器
public class PlayerVillageMove : MonoBehaviour {

    public float velocity=5;

// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
        float h = Input.GetAxis("Horizontal");
        float v = Input.GetAxis("Vertical");
        Vector3 vel = gameObject.GetComponent<Rigidbody>().velocity;
        gameObject.GetComponent<Rigidbody>().velocity=new Vector3(-h*velocity, vel.y, -v*velocity);
        if (Mathf.Abs(h)>0.05f||Mathf.Abs(v)>0/05f)
        {
       transform.rotation=     Quaternion.LookRotation(new Vector3(-h, 0, -v));
        }
}

}

第一人称角色控制器 


private CharacterController controller;

public int =speed=10;

void Statr(){

contoller=this.GetCompontent<CharachercaterController>();

}

void Update(){

controller.SimpleMove(new Vecotr3(Input.GetAcis("Horizontal")*speed,0,Input.GetAcis("Vertical")*speed ));

}


原创粉丝点击