Groundcheck ist jetzt eine sphere

This commit is contained in:
2024-07-03 12:38:08 +02:00
parent 6f29dd08ba
commit 1411eb68c9
3 changed files with 33 additions and 24 deletions

View File

@@ -10,7 +10,9 @@ public class PlayerMoveScript : MonoBehaviour
[Header("Movement")]
[SerializeField] private float speed;
[SerializeField] private float jumpForce;
[SerializeField] private float checkForJump;
[SerializeField] private float jumpPointDistance;
[SerializeField] private float jumpPointRadius;
[Header("Looking")]
[SerializeField] private float xSensitivity;
[SerializeField] private float ySensitivity;
@@ -18,6 +20,7 @@ public class PlayerMoveScript : MonoBehaviour
private Rigidbody rb;
private bool cursorIsLocked;
private LayerMask ground;
void Start()
{
@@ -25,15 +28,7 @@ public class PlayerMoveScript : MonoBehaviour
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
ground = LayerMask.GetMask("Ground");
}
// Update is called once per frame
@@ -67,7 +62,7 @@ public class PlayerMoveScript : MonoBehaviour
{
if(Input.GetKey(KeyCode.Space))
{
if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.down), checkForJump))
if (Physics.CheckSphere(transform.position + Vector3.down * jumpPointDistance, jumpPointRadius, ground) )
{
rb.isKinematic = true;
rb.isKinematic = false;
@@ -81,8 +76,14 @@ public class PlayerMoveScript : MonoBehaviour
{
// Draws a Line for checkForJump
Gizmos.color = Color.red;
Vector3 direction = transform.TransformDirection(Vector3.down) * checkForJump;
Vector3 direction = transform.TransformDirection(Vector3.down) * jumpPointDistance;
Gizmos.DrawRay(transform.position, direction);
// Draw a yellow sphere at the transform's position
Gizmos.color = Color.blue;
Gizmos.DrawWireSphere(transform.position + Vector3.down * jumpPointDistance, jumpPointRadius);
}
public float newDirY;