Spieler kann springen und hat Fadenkreuz(platzhalter)
This commit is contained in:
@@ -1,16 +1,21 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using Unity.VisualScripting;
|
||||
using UnityEngine;
|
||||
|
||||
public class PlayerMoveScript : MonoBehaviour
|
||||
{
|
||||
|
||||
public float speed;
|
||||
public float xSensitivity;
|
||||
public float ySensitivity;
|
||||
[Header("Movement")]
|
||||
[SerializeField] private float speed;
|
||||
[SerializeField] private float jumpForce;
|
||||
[SerializeField] private float checkForJump;
|
||||
[Header("Looking")]
|
||||
[SerializeField] private float xSensitivity;
|
||||
[SerializeField] private float ySensitivity;
|
||||
[SerializeField] private Camera cam;
|
||||
private Rigidbody rb;
|
||||
public Camera cam;
|
||||
|
||||
private bool cursorIsLocked;
|
||||
|
||||
@@ -23,6 +28,15 @@ public class PlayerMoveScript : MonoBehaviour
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
move();
|
||||
look();
|
||||
lockCursor();
|
||||
jump();
|
||||
}
|
||||
|
||||
|
||||
public void move()
|
||||
{
|
||||
// In welche Richtung rennt der Spieler?
|
||||
int moveDirX = 0;;
|
||||
@@ -37,11 +51,26 @@ public class PlayerMoveScript : MonoBehaviour
|
||||
moveDir.Normalize();
|
||||
|
||||
rb.velocity = transform.TransformDirection(new Vector3(moveDir.x * speed, rb.velocity.y, moveDir.z * speed));
|
||||
}
|
||||
|
||||
public void jump()
|
||||
{
|
||||
if(Input.GetKeyDown(KeyCode.Space))
|
||||
{
|
||||
if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.down), checkForJump))
|
||||
{
|
||||
rb.AddForce(Vector3.up * jumpForce, ForceMode.Impulse);
|
||||
}
|
||||
}
|
||||
|
||||
look();
|
||||
|
||||
lockCursor();
|
||||
}
|
||||
|
||||
void OnDrawGizmosSelected()
|
||||
{
|
||||
// Draws a Line for checkForJump
|
||||
Gizmos.color = Color.red;
|
||||
Vector3 direction = transform.TransformDirection(Vector3.down) * checkForJump;
|
||||
Gizmos.DrawRay(transform.position, direction);
|
||||
}
|
||||
|
||||
public void look()
|
||||
|
Reference in New Issue
Block a user