Browse Source

Working on running

master
Ken Schaefer 5 years ago
parent
commit
bda6ed09ce
  1. 16
      Assets/FirstPersonController/Scripts/PlayerMovement.cs
  2. 16
      Assets/FirstPersonController/Variables/PlayerRunSpeed.asset
  3. 8
      Assets/FirstPersonController/Variables/PlayerRunSpeed.asset.meta
  4. 2
      Assets/FirstPersonController/Variables/PlayerWalkSpeed.asset
  5. 0
      Assets/FirstPersonController/Variables/PlayerWalkSpeed.asset.meta

16
Assets/FirstPersonController/Scripts/PlayerMovement.cs

@ -23,7 +23,8 @@ public class PlayerMovement : MonoBehaviour
[SerializeField] private CharacterController controller;
[Header("Attributes")]
[SerializeField] private FloatReference playerSpeed;
[SerializeField] private FloatReference playerWalkSpeed;
[SerializeField] private FloatReference playerRunSpeed;
[SerializeField] private FloatReference jumpHeight;
[Header("Environment")]
@ -50,10 +51,19 @@ public class PlayerMovement : MonoBehaviour
float z = Input.GetAxis("Vertical");
Vector3 move = transform.right * x + transform.forward * z;
controller.Move(move * playerSpeed.Value * Time.deltaTime);
if (Input.GetKeyDown(KeyCode.LeftShift) && isGrounded)
{
Debug.Log("Running");
controller.Move(move * playerRunSpeed * Time.deltaTime);
}
else
{
Debug.Log("Walking");
controller.Move(move * playerWalkSpeed.Value * Time.deltaTime);
}
// Implement jumping
if(Input.GetButtonDown("Jump") && isGrounded)
if (Input.GetButtonDown("Jump") && isGrounded)
{
velocity.y = Mathf.Sqrt(jumpHeight.Value * -2f * gravity.Value);
}

16
Assets/FirstPersonController/Variables/PlayerRunSpeed.asset

@ -0,0 +1,16 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 7cb18c6bb3c4bcd40b8451100e11b136, type: 3}
m_Name: PlayerRunSpeed
m_EditorClassIdentifier:
DeveloperDescription:
Value: 36

8
Assets/FirstPersonController/Variables/PlayerRunSpeed.asset.meta

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: e96483bba2736bb499237d1aa26f580a
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 0
userData:
assetBundleName:
assetBundleVariant:

2
Assets/FirstPersonController/Variables/PlayerSpeed.asset → Assets/FirstPersonController/Variables/PlayerWalkSpeed.asset

@ -10,7 +10,7 @@ MonoBehaviour:
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 7cb18c6bb3c4bcd40b8451100e11b136, type: 3}
m_Name: PlayerSpeed
m_Name: PlayerWalkSpeed
m_EditorClassIdentifier:
DeveloperDescription:
Value: 12

0
Assets/FirstPersonController/Variables/PlayerSpeed.asset.meta → Assets/FirstPersonController/Variables/PlayerWalkSpeed.asset.meta

Loading…
Cancel
Save