Look() Methode in Movement Script ist Fertig. yBewegung beim gucken wird geclampt
This commit is contained in:
@@ -24,6 +24,16 @@ public class PlayerMoveScript : MonoBehaviour
|
||||
rb = GetComponent<Rigidbody>();
|
||||
Cursor.lockState = CursorLockMode.Locked;
|
||||
cursorIsLocked = true;
|
||||
|
||||
float degree = 100.0f; // Beispielwert, der außerhalb des Bereichs liegt
|
||||
|
||||
degree = Mathf.Clamp(degree, -90, 90);
|
||||
Debug.Log(degree); // Ausgabe: 90
|
||||
|
||||
degree = -100.0f; // Beispielwert, der außerhalb des Bereichs liegt
|
||||
|
||||
degree = Mathf.Clamp(degree, -90, 90);
|
||||
Debug.Log(degree); // Ausgabe: -90
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
@@ -59,6 +69,7 @@ public class PlayerMoveScript : MonoBehaviour
|
||||
{
|
||||
if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.down), checkForJump))
|
||||
{
|
||||
rb.velocity = new Vector3(rb.velocity.x, 0, rb.velocity.z);
|
||||
rb.AddForce(Vector3.up * jumpForce, ForceMode.Impulse);
|
||||
}
|
||||
}
|
||||
@@ -73,6 +84,7 @@ public class PlayerMoveScript : MonoBehaviour
|
||||
Gizmos.DrawRay(transform.position, direction);
|
||||
}
|
||||
|
||||
public float newDirY;
|
||||
public void look()
|
||||
{
|
||||
float xMouseMovement = Input.GetAxis("Mouse X") * xSensitivity * Time.deltaTime;
|
||||
@@ -81,10 +93,11 @@ public class PlayerMoveScript : MonoBehaviour
|
||||
Vector3 currentRotation = cam.transform.rotation.eulerAngles;
|
||||
|
||||
float newDirX = currentRotation.y + xMouseMovement;
|
||||
float newDirY = currentRotation.x - yMouseMovement;
|
||||
newDirY = newDirY - yMouseMovement;
|
||||
newDirY = Mathf.Clamp(newDirY, -90f, 90f);
|
||||
|
||||
cam.transform.localRotation = Quaternion.Euler(newDirY, 0, 0);
|
||||
transform.rotation = Quaternion.Euler(0, newDirX, 0);
|
||||
transform.localRotation = Quaternion.Euler(0, newDirX, 0);
|
||||
}
|
||||
|
||||
public void lockCursor()
|
||||
|
Reference in New Issue
Block a user