zoukankan      html  css  js  c++  java
  • 人物根据镜头方向旋转和移动

    人物根据镜头方向转身

    float ver = 0;
    float hor = 0;
    void Rotating (float hor, float ver)
    {
    //获取方向
    Vector3 dir = new Vector3 (hor,0,ver);
    float y = Camera.main.transform.rotation.eulerAngles.y;
    dir = Quaternion.Euler(0, y, 0) * dir;

    //将方向转换为四元数
    Quaternion quaDir = Quaternion.LookRotation(dir,Vector3.up);
    //缓慢转动到目标点
    transform.rotation = Quaternion.Lerp(transform.rotation,quaDir,Time.fixedDeltaTime*turnspeed);
    }

    void FixedUpdate()
    {

    if (hor != 0 || ver != 0)
    {
    //转身
    Rotating(hor, ver);

    }
    }

    人物根据镜头方向移动

    bool Move()
    {

    hor = Input.GetAxis("Horizontal");
    ver = Input.GetAxis("Vertical");


    Vector3 targetDirection = new Vector3(hor, 0, ver);
    float y = Camera.main.transform.rotation.eulerAngles.y;
    targetDirection = Quaternion.Euler(0, y, 0) * targetDirection;


    if (Input.GetKey(KeyCode.W))
    {

    GetComponent<Animator>().SetBool("Walk", true);
    transform.Translate(targetDirection * Time.deltaTime * 1, Space.World);
    return true;
    }
    if (Input.GetKey(KeyCode.S))
    {

    GetComponent<Animator>().SetBool("Walk", true);
    transform.Translate(targetDirection * Time.deltaTime * 1, Space.World);
    return true;
    }
    if (Input.GetKey(KeyCode.A))
    {

    GetComponent<Animator>().SetBool("Walk", true);
    transform.Translate(targetDirection * Time.deltaTime * 1, Space.World);
    return true;
    }
    if (Input.GetKey(KeyCode.D))
    {

    GetComponent<Animator>().SetBool("Walk", true);
    transform.Translate(targetDirection * Time.deltaTime * 1, Space.World);
    return true;
    }


    return false;

    }

  • 相关阅读:
    强化训练1
    强化训练2
    变量的本质
    抽象层
    安装vs2015
    解决思路
    分析栈的缺点
    (转)使用yuicompressor-maven-plugin压缩js及css文件(二)
    (转)yuicompressor 与 maven结合,打包,压缩js,css (一)
    (转)Properties Editor为你解除通过native2ascii进行Unicode转码的烦恼
  • 原文地址:https://www.cnblogs.com/tqvdong/p/14269393.html
Copyright © 2011-2022 走看看