mirror of
https://github.com/DerTyp7/fps-citybuild-unity.git
synced 2025-10-29 20:22:08 +01:00
basic air control and sprinting
This commit is contained in:
@@ -733,8 +733,11 @@ MonoBehaviour:
|
|||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
controller: {fileID: 1023538875}
|
controller: {fileID: 1023538875}
|
||||||
speed: 12
|
speed: 12
|
||||||
|
airSpeed: 0.7
|
||||||
|
sprintSpeed: 1.8
|
||||||
|
sprintAirSpeed: 1.2
|
||||||
gravity: -19.62
|
gravity: -19.62
|
||||||
jumpHeight: 3
|
jumpHeight: 4
|
||||||
groundCheck: {fileID: 1403327789}
|
groundCheck: {fileID: 1403327789}
|
||||||
groundDistance: 0.4
|
groundDistance: 0.4
|
||||||
groundMask:
|
groundMask:
|
||||||
|
|||||||
@@ -6,7 +6,11 @@ public class PlayerMovement : MonoBehaviour
|
|||||||
{
|
{
|
||||||
|
|
||||||
[SerializeField] private CharacterController controller;
|
[SerializeField] private CharacterController controller;
|
||||||
|
//[SerializeField] private Transform playerTransform;
|
||||||
[SerializeField] private float speed = 12f;
|
[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 gravity = -9.81f;
|
||||||
[SerializeField] private float jumpHeight = 3f;
|
[SerializeField] private float jumpHeight = 3f;
|
||||||
|
|
||||||
@@ -16,6 +20,7 @@ public class PlayerMovement : MonoBehaviour
|
|||||||
|
|
||||||
private Vector3 velocity;
|
private Vector3 velocity;
|
||||||
private bool isGrounded;
|
private bool isGrounded;
|
||||||
|
private bool isSprinting;
|
||||||
|
|
||||||
void Start()
|
void Start()
|
||||||
{
|
{
|
||||||
@@ -24,7 +29,8 @@ public class PlayerMovement : MonoBehaviour
|
|||||||
|
|
||||||
|
|
||||||
void Update()
|
void Update()
|
||||||
{
|
{
|
||||||
|
//GROUND CHECK
|
||||||
//Creates an invisible sphere on the bottom of our player
|
//Creates an invisible sphere on the bottom of our player
|
||||||
//And checks if it's colliding with something !with the "ground"-Mask in Unity!
|
//And checks if it's colliding with something !with the "ground"-Mask in Unity!
|
||||||
isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, groundMask);
|
isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, groundMask);
|
||||||
@@ -34,30 +40,60 @@ public class PlayerMovement : MonoBehaviour
|
|||||||
{
|
{
|
||||||
velocity.y = -2f;
|
velocity.y = -2f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//MOVEMENT
|
||||||
//Input.GetAxis is based on the Unity Input settings (edit -> Project Settings -> Input Manager)
|
//Input.GetAxis is based on the Unity Input settings (edit -> Project Settings -> Input Manager)
|
||||||
float x = Input.GetAxis("Horizontal");
|
float x = Input.GetAxis("Horizontal");
|
||||||
float z = Input.GetAxis("Vertical");
|
float z = Input.GetAxis("Vertical");
|
||||||
|
|
||||||
//Create move vector !in look direction!
|
//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
|
//Apply move vector
|
||||||
controller.Move(move * speed * Time.deltaTime);
|
controller.Move(move * speed * Time.deltaTime);
|
||||||
|
|
||||||
//JUMP
|
|
||||||
if(Input.GetButtonDown("Jump") && isGrounded)
|
|
||||||
{
|
|
||||||
velocity.y = Mathf.Sqrt(jumpHeight * -2f * gravity);
|
|
||||||
}
|
|
||||||
|
|
||||||
//Add gravity to current velocity
|
//Add gravity to current velocity
|
||||||
velocity.y += gravity * Time.deltaTime;
|
velocity.y += gravity * Time.deltaTime;
|
||||||
//apply gravity
|
//apply gravity
|
||||||
controller.Move(velocity * Time.deltaTime);//nochmal time.deltatime wegen irgendwas mit physikalischer Formel und so
|
controller.Move(velocity * Time.deltaTime);//nochmal time.deltatime wegen irgendwas mit physikalischer Formel und so
|
||||||
}
|
|
||||||
|
|
||||||
void Jump()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -293,3 +293,19 @@ InputManager:
|
|||||||
type: 0
|
type: 0
|
||||||
axis: 0
|
axis: 0
|
||||||
joyNum: 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
|
||||||
|
|||||||
@@ -152,7 +152,8 @@ PlayerSettings:
|
|||||||
resolutionScalingMode: 0
|
resolutionScalingMode: 0
|
||||||
androidSupportedAspectRatio: 1
|
androidSupportedAspectRatio: 1
|
||||||
androidMaxAspectRatio: 2.1
|
androidMaxAspectRatio: 2.1
|
||||||
applicationIdentifier: {}
|
applicationIdentifier:
|
||||||
|
Standalone: com.DefaultCompany.FirstPersonRME
|
||||||
buildNumber:
|
buildNumber:
|
||||||
Standalone: 0
|
Standalone: 0
|
||||||
iPhone: 0
|
iPhone: 0
|
||||||
|
|||||||
Reference in New Issue
Block a user