英文:
"cannot convert from 'UnityEngine.Vector3' to 'UnityEngine.Space" trying to rotate camera with joystick
问题
以下是翻译好的部分:
"我想使用摇杆在水平方向上旋转相机,但出现了错误。
无法从 'UnityEngine.Vector3' 转换为 'UnityEngine.Space'
transform.Rotate(Vector3.up, direction * rotationSpeed * Time.deltaTime);
如果我从上面的代码中移除Vector3.up,错误就会消失,我可以使用摇杆移动相机,但它会在垂直方向上旋转。有没有办法修复这个问题?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RotateCamera : MonoBehaviour
{
public float rotationSpeed = 50.0f;
public VariableJoystick variableJoystick;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
//float horizontalInput = Input.GetAxis("Horizontal");
//transform.Rotate(Vector3.up, horizontalInput * rotationSpeed * Time.deltaTime);
Vector3 direction = Vector3.forward * variableJoystick.Vertical + Vector3.right * variableJoystick.Horizontal;
transform.Rotate(Vector3.up, direction * rotationSpeed * Time.deltaTime);
}
}
英文:
so i want to rotate the camera horizontally with joystick but it is giving me an error.
cannot convert from 'UnityEngine.Vector3' to 'UnityEngine.Space'
transform.Rotate(Vector3.up, direction * rotationSpeed * Time.deltaTime);
if i remove Vector3.up from the code above the error goes away and i can move the camera with joystick but its rotating vertically. Any way to fix this?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RotateCamera : MonoBehaviour
{
public float rotationSpeed = 50.0f;
public VariableJoystick variableJoystick;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
//float horizontalInput = Input.GetAxis("Horizontal");
//transform.Rotate(Vector3.up, horizontalInput * rotationSpeed * Time.deltaTime);
Vector3 direction = Vector3.forward * variableJoystick.Vertical + Vector3.right * variableJoystick.Horizontal;
transform.Rotate(Vector3.up, direction * rotationSpeed * Time.deltaTime);
}
}
答案1
得分: 1
我猜你想要:
transform.Rotate(Vector3.up * variableJoystick.Horizontal * rotationSpeed * Time.deltaTime);
然后,或者也许更容易阅读的是:
transform.Rotate(0, variableJoystick.Horizontal * rotationSpeed * Time.deltaTime, 0);
英文:
I guess you want
transform.Rotate(Vector3.up * variableJoystick.Horizontal * rotationSpeed * Time.deltaTime);
then, or also maybe easier to read
transform.Rotate(0, variableJoystick.Horizontal * rotationSpeed * Time.deltaTime, 0);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论