发布网友 发布时间:2022-04-09 13:01
共3个回答
懂视网 时间:2022-04-09 17:22
void Turning()
{
// Create a ray from the mouse cursor on screen in the direction of the camera.
Ray camRay = Camera.main.ScreenPointToRay(Input.mousePosition);
// Create a RaycastHit variable to store information about what was hit by the ray.
RaycastHit floorHit;
// Perform the raycast and if it hits something on the floor layer...
if (Physics.Raycast(camRay, out floorHit, camRayLength, floorMask))
{
// Create a vector from the player to the point on the floor the raycast from the mouse hit.
Vector3 playerToMouse = floorHit.point - transform.position;
// Ensure the vector is entirely along the floor plane.
playerToMouse.y = 0f;
// Create a quaternion (rotation) based on looking down the vector from the player to the mouse.
Quaternion newRotatation = Quaternion.LookRotation(playerToMouse);
// Set the player‘s rotation to this new rotation.
m_Rigidbody.MoveRotation(newRotatation);
}
Rigidbody相关的操作最好放在FixedUpdate中,update中可能会无效果
标签:rto nio poi put something ase direct new 相关
热心网友 时间:2022-04-09 14:30
今天有人问我问什么我在处理物理逻辑的时候把代码放在了FixedUpdate里,而不用Update?热心网友 时间:2022-04-09 15:48
Update是在每次渲染新的一帧的时候才会调用