具有沿腔室方向移动旋转的旋转刚体

问题描述 投票:0回答:1

[我想像普通的第三人称射击游戏一样,使用moverotation沿主相机的方向旋转对象,但是我不知道如何设置四元数值]]

`using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class movimento : MonoBehaviour
{

   [SerializeField] float walk = 1;
   [SerializeField] float run = 2;
    Vector3 movement = Vector3.zero;
    private Rigidbody rig;

    // Start is called before the first frame update
    void Start()
    {
      rig = GetComponent<Rigidbody>();
    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.LeftShift)) walk = (walk + run);
        if (Input.GetKeyUp(KeyCode.LeftShift)) walk = (walk - run);

        float Horizontal = Input.GetAxis("Horizontal");.
        float Vertical = Input.GetAxis("Vertical");
        movement = Camera.main.transform.forward * Vertical + Camera.main.transform.right * Horizontal;
        float origMagnitude = movement.magnitude;
        movement.y = 0f;
        movement = movement.normalized * origMagnitude;

    }

     private void FixedUpdate ()
    {
        rig.MovePosition(rig.position + movement * walk * Time.fixedDeltaTime);
        Quaternion rotation = Quaternion.Euler(???);
        rig.MoveRotation(rig.rotation * rotation);


    }
  }`

[我想像普通的第三人称射击游戏一样,使用moverotation沿主相机的方向旋转对象,但是我不知道如何设置四元数值,或者不知道如何使用System...。

c# unity3d rotation quaternions direction
1个回答
0
投票

我使用协程进行平滑旋转。

so

© www.soinside.com 2019 - 2024. All rights reserved.