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;

    }

  • 相关阅读:
    PGL:Paddle带你走进图学习
    Improving the way neural networks learn
    文本语义匹配Simnet模型
    图卷积神经网络(GCN)
    git revert
    vi/vim多行注释和取消注释、复制粘贴
    谷歌之多任务学习模型MMoE
    阿里CVR预估模型之ESMM
    知识图谱简介
    CTR预估--Deep Interest Network
  • 原文地址:https://www.cnblogs.com/tqvdong/p/14269393.html
Copyright © 2011-2022 走看看