Gottfried kann sich bewegen und drehen

This commit is contained in:
2024-04-05 18:37:40 +02:00
parent b7375f945f
commit 7097644bc2
3 changed files with 102 additions and 274 deletions

View File

@ -15,6 +15,10 @@ public class Character : MonoBehaviour
public float speed = 2f;
[Header("Turning")]
public float turningRate = 30f;
public Quaternion _targetRotation = Quaternion.identity;
[Header("Keybindings")]
public KeyCode jumpKey = KeyCode.Space;
@ -41,6 +45,8 @@ public class Character : MonoBehaviour
MyInput();
SpeedControl();
transform.rotation = Quaternion.RotateTowards(transform.rotation, _targetRotation, turningRate * Time.deltaTime);
if (grounded)
{
rb.drag = groundDrag;
@ -62,7 +68,11 @@ public class Character : MonoBehaviour
horizontalInput = Input.GetAxisRaw("Horizontal");
verticalInput = Input.GetAxisRaw("Vertical");
if(horizontalInput != 0f || verticalInput != 0f)
{
_targetRotation = Quaternion.Euler(new Vector3(0f, Mathf.Atan2(horizontalInput, verticalInput) * Mathf.Rad2Deg, 0f));
}
if (Input.GetKey(jumpKey) && readyToJump && grounded)
{
readyToJump = false;