basic air control and sprinting

This commit is contained in:
DerTyp187
2021-09-21 18:34:02 +02:00
parent 61294cb761
commit e3064f0823
4 changed files with 72 additions and 16 deletions

View File

@@ -733,8 +733,11 @@ MonoBehaviour:
m_EditorClassIdentifier:
controller: {fileID: 1023538875}
speed: 12
airSpeed: 0.7
sprintSpeed: 1.8
sprintAirSpeed: 1.2
gravity: -19.62
jumpHeight: 3
jumpHeight: 4
groundCheck: {fileID: 1403327789}
groundDistance: 0.4
groundMask:

View File

@@ -6,7 +6,11 @@ public class PlayerMovement : MonoBehaviour
{
[SerializeField] private CharacterController controller;
//[SerializeField] private Transform playerTransform;
[SerializeField] private float speed = 12f;
[SerializeField] private float airSpeed = 0.6f;
[SerializeField] private float sprintSpeed = 1.8f;
[SerializeField] private float sprintAirSpeed = 1.2f;
[SerializeField] private float gravity = -9.81f;
[SerializeField] private float jumpHeight = 3f;
@@ -16,6 +20,7 @@ public class PlayerMovement : MonoBehaviour
private Vector3 velocity;
private bool isGrounded;
private bool isSprinting;
void Start()
{
@@ -24,7 +29,8 @@ public class PlayerMovement : MonoBehaviour
void Update()
{
{
//GROUND CHECK
//Creates an invisible sphere on the bottom of our player
//And checks if it's colliding with something !with the "ground"-Mask in Unity!
isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, groundMask);
@@ -34,30 +40,60 @@ public class PlayerMovement : MonoBehaviour
{
velocity.y = -2f;
}
//MOVEMENT
//Input.GetAxis is based on the Unity Input settings (edit -> Project Settings -> Input Manager)
float x = Input.GetAxis("Horizontal");
float z = Input.GetAxis("Vertical");
//Create move vector !in look direction!
Vector3 move = transform.right * x + transform.forward * z;
Vector3 move;
if (isGrounded)//for air control
{
move = transform.right * x + transform.forward * z;
//SPRINT
if (Input.GetButton("Sprint"))
{
move *= sprintSpeed;
isSprinting = true;
}
else
{
//SNEAK
if (Input.GetButton("Sneak"))
{
//Kommt mit character model und animations
}
isSprinting = false;
}
//JUMP
if (Input.GetButtonDown("Jump"))
{
velocity.y = Mathf.Sqrt(jumpHeight * -2f * gravity);
}
}
else//Air control
{
if (isSprinting)
{
move = transform.right * x * airSpeed * sprintAirSpeed + transform.forward * z * airSpeed * sprintAirSpeed;
}
else
{
move = transform.right * x * airSpeed + transform.forward * z * airSpeed;
}
}
//Apply move vector
controller.Move(move * speed * Time.deltaTime);
//JUMP
if(Input.GetButtonDown("Jump") && isGrounded)
{
velocity.y = Mathf.Sqrt(jumpHeight * -2f * gravity);
}
//Add gravity to current velocity
velocity.y += gravity * Time.deltaTime;
//apply gravity
controller.Move(velocity * Time.deltaTime);//nochmal time.deltatime wegen irgendwas mit physikalischer Formel und so
}
void Jump()
{
}
}

View File

@@ -293,3 +293,19 @@ InputManager:
type: 0
axis: 0
joyNum: 0
- serializedVersion: 3
m_Name: Sprint
descriptiveName:
descriptiveNegativeName:
negativeButton:
positiveButton: left ctrl
altNegativeButton:
altPositiveButton:
gravity: 1000
dead: 0.001
sensitivity: 1000
snap: 0
invert: 0
type: 0
axis: 0
joyNum: 0

View File

@@ -152,7 +152,8 @@ PlayerSettings:
resolutionScalingMode: 0
androidSupportedAspectRatio: 1
androidMaxAspectRatio: 2.1
applicationIdentifier: {}
applicationIdentifier:
Standalone: com.DefaultCompany.FirstPersonRME
buildNumber:
Standalone: 0
iPhone: 0