Merge commit '6699035d665f097663b6b9d70f0a9fb6efff3483'
This commit is contained in:
@@ -176,6 +176,37 @@ PrefabInstance:
|
||||
m_AddedGameObjects: []
|
||||
m_AddedComponents: []
|
||||
m_SourcePrefab: {fileID: 100100000, guid: b7eb279b00f6fbf4bb09461381196875, type: 3}
|
||||
--- !u!1 &1074333935
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 1074333936}
|
||||
m_Layer: 0
|
||||
m_Name: LegsPosition
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!4 &1074333936
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1074333935}
|
||||
serializedVersion: 2
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: -0.9, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 2060574367}
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!1 &1560783767
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
@@ -309,7 +340,7 @@ GameObject:
|
||||
- component: {fileID: 1692628190}
|
||||
- component: {fileID: 1692628189}
|
||||
- component: {fileID: 1692628188}
|
||||
m_Layer: 0
|
||||
m_Layer: 6
|
||||
m_Name: Cube
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
@@ -581,6 +612,11 @@ MonoBehaviour:
|
||||
crouchHeightMultiplier: 0.5
|
||||
jumpForce: 5
|
||||
gravityMultiplier: 1
|
||||
legsPosition: {fileID: 1074333936}
|
||||
legsRadius: 0.2
|
||||
groundMask:
|
||||
serializedVersion: 2
|
||||
m_Bits: 64
|
||||
isCrouching: 0
|
||||
--- !u!143 &2060574363
|
||||
CharacterController:
|
||||
@@ -674,6 +710,7 @@ Transform:
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children:
|
||||
- {fileID: 1907799224}
|
||||
- {fileID: 1074333936}
|
||||
m_Father: {fileID: 0}
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!114 &2060574368
|
||||
|
||||
@@ -2,24 +2,31 @@ using UnityEngine;
|
||||
|
||||
public class PlayerMovement : MonoBehaviour
|
||||
{
|
||||
[Header("Horizontal movement")]
|
||||
public float speed = 1f;
|
||||
public float sprintSpeedMultiplier = 2f;
|
||||
public float crouchSpeedMultiplier = 0.5f;
|
||||
public float crouchHeightMultiplier = 0.5f;
|
||||
[Header("Vertical movement")]
|
||||
public float jumpForce = 1f;
|
||||
public float gravityMultiplier = 1f;
|
||||
public Transform legsPosition;
|
||||
public float legsRadius = 0.5f;
|
||||
public LayerMask groundMask;
|
||||
|
||||
[Header("Debug info")]
|
||||
[SerializeField] bool isCrouching = false;
|
||||
[SerializeField] Vector3 gravityVelocity;
|
||||
[SerializeField] bool grounded;
|
||||
|
||||
CharacterController characterController;
|
||||
[SerializeField] bool isCrouching = false;
|
||||
Vector3 gravityVelocity;
|
||||
bool grounded;
|
||||
|
||||
void Start() {
|
||||
characterController = GetComponent<CharacterController>();
|
||||
}
|
||||
|
||||
void Update() {
|
||||
grounded = characterController.isGrounded;
|
||||
grounded = GetOnGround();
|
||||
HandleCrouching();
|
||||
HandleMovement();
|
||||
HandleJumping();
|
||||
@@ -36,12 +43,11 @@ public class PlayerMovement : MonoBehaviour
|
||||
characterController.height /= crouchHeightMultiplier;
|
||||
characterController.center -= Vector3.down * (characterController.height * (1 - crouchHeightMultiplier)) / 2;
|
||||
}
|
||||
// if (characterController.isGrounded) rb.AddForce(Vector3.up * (characterController.height / 5), ForceMode.VelocityChange);
|
||||
}
|
||||
}
|
||||
|
||||
void HandleJumping() {
|
||||
if (Input.GetKeyDown(KeyCode.Space) && grounded) {
|
||||
if (Input.GetKey(KeyCode.Space) && grounded) {
|
||||
gravityVelocity = Vector3.up * (jumpForce * gravityMultiplier);
|
||||
}
|
||||
}
|
||||
@@ -58,11 +64,15 @@ public class PlayerMovement : MonoBehaviour
|
||||
}
|
||||
|
||||
void DoGravity() {
|
||||
if (grounded && gravityVelocity.y < 0) gravityVelocity = Vector3.down * 0.5f;
|
||||
if (grounded && gravityVelocity.y < 0) gravityVelocity = Vector3.zero;
|
||||
gravityVelocity += Physics.gravity * Time.deltaTime;
|
||||
characterController.Move(gravityVelocity * (Time.deltaTime * gravityMultiplier));
|
||||
}
|
||||
|
||||
bool GetOnGround() {
|
||||
return Physics.CheckSphere(legsPosition.position, legsRadius, groundMask);
|
||||
}
|
||||
|
||||
void OnControllerColliderHit(ControllerColliderHit hit) {
|
||||
hit.gameObject.SendMessage("ReverseOnControllerColliderHit", hit, SendMessageOptions.DontRequireReceiver);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!78 &1
|
||||
TagManager:
|
||||
serializedVersion: 2
|
||||
serializedVersion: 3
|
||||
tags: []
|
||||
layers:
|
||||
- Default
|
||||
@@ -11,7 +11,7 @@ TagManager:
|
||||
-
|
||||
- Water
|
||||
- UI
|
||||
-
|
||||
- Ground
|
||||
-
|
||||
-
|
||||
-
|
||||
@@ -50,27 +50,3 @@ TagManager:
|
||||
- Light Layer 5
|
||||
- Light Layer 6
|
||||
- Light Layer 7
|
||||
-
|
||||
-
|
||||
-
|
||||
-
|
||||
-
|
||||
-
|
||||
-
|
||||
-
|
||||
-
|
||||
-
|
||||
-
|
||||
-
|
||||
-
|
||||
-
|
||||
-
|
||||
-
|
||||
-
|
||||
-
|
||||
-
|
||||
-
|
||||
-
|
||||
-
|
||||
-
|
||||
-
|
||||
|
||||
Reference in New Issue
Block a user