英文:
Unity player movement issue
问题
I was trying to follow brackeys tutorial on player controller, but the code is not working.
Here's the code:
using UnityEngine;
public class Mouse_Look : MonoBehaviour
{
public float mousesen = 100f;
public Transform playerBody;
float xRotation = 0f;
// Start is called before the first frame update
void Start()
{
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
}
// Update is called once per frame
void Update()
{
float mouseX = Input.GetAxis("Mouse X") * Time.deltaTime * mousesen;
float mouseY = Input.GetAxis("Mouse Y") * Time.deltaTime * mousesen;
xRotation -= mouseY;
xRotation = Mathf.Clamp(xRotation, -90f , 90f );
transform.localRotation=Quaternion.Euler(xRotation,0f,0f);
playerBody.Rotate(Vector3.up * mouseX);
}
}
What should I do??
英文:
I was trying to follow brackeys tutorial on player controller, but the code is not working.
Here's the code:
using UnityEngine;
public class Mouse_Look : MonoBehaviour
{
public float mousesen = 100f;
public Transform playerBody;
float xRotation = 0f;
// Start is called before the first frame update
void Start()
{
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
}
// Update is called once per frame
void Update()
{
float mouseX = Input.GetAxis("Mouse X") * Time.deltaTime * mousesen;
float mouseY = Input.GetAxis("Mouse Y") * Time.deltaTime * mousesen;
xRotation -= mouseY;
xRotation = Mathf.Clamp(xRotation, -90f , 90f );
transform.localRotation=Quaternion.Euler(xRotation,0f,0f);
playerBody.Rotate=(Vector3 up * mouseX);
}
}
What should I do??
答案1
得分: 1
transform.Rotate
是一个方法,而不是一个属性,因此
playerBody.Rotate=(Vector3 up * mouseX);
应该是
playerBody.Rotate(Vector3.up * mouseX, playerBody.rotation.y, playerBody.rotation.y);
英文:
transform.Rotate
is a method, not a property, so
playerBody.Rotate=(Vector3 up * mouseX);
should be
playerBody.Rotate(Vector3.up * mouseX, playerBody.rotation.y, playerBody.rotation.y);
答案2
得分: 0
应该是 playerBody.Rotate()
而不是 playerBody.Rotate=()
。
英文:
It should be playerBody.Rotate()
instead of playerBody.Rotate=()
.
答案3
得分: 0
这个部分已翻译:
这个 playerBody.Rotate=(Vector3 up * mouseX);
应该是 playerBody.Rotate(Vector3 up * mouseX);
Rotate 是一个接受一个 Vector3 的方法。我建议花点时间来了解 Unity 中的旋转 基础知识,而不仅仅是从教程中复制粘贴代码。这可能会修复错误,但你将不得不每次都查找教程。
英文:
This playerBody.Rotate=(Vector3 up * mouseX);
Should be playerBody.Rotate(Vector3 up * mouseX);
Rotate is method that takes in a vector 3. I suggest taking some time to understand the basics of rotation in Unity, rather than just copy pasting codes from tutorial. This might fix the error, but you will have to look for tutorial every time.
答案4
得分: 0
playerBody.Rotate=(Vector3 up * mouseX);
转换为 playerBody.Rotate(Vector3.up * mouseX);
,因为".Rotate"是一个方法,不需要"="。 干杯,伙计!
英文:
playerBody.Rotate=(Vector3 up * mouseX); to playerBody.Rotate(Vector3.up * mouseX);
because ".Rotate" is method. you don't need "=". cheers mate!
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论