mirror of
https://github.com/ConjureETS/EscapeTheRoom.git
synced 2026-03-25 17:50:58 +00:00
Personnage firstPerson
This commit is contained in:
parent
7630be8ffa
commit
5c75c7412f
9
Assets/Sound.meta
Normal file
9
Assets/Sound.meta
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: e2839cc8e19d8dc4098d710783dbac88
|
||||||
|
folderAsset: yes
|
||||||
|
timeCreated: 1446922484
|
||||||
|
licenseType: Free
|
||||||
|
DefaultImporter:
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -0,0 +1,306 @@
|
|||||||
|
%YAML 1.1
|
||||||
|
%TAG !u! tag:unity3d.com,2011:
|
||||||
|
--- !u!1 &100000
|
||||||
|
GameObject:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_PrefabParentObject: {fileID: 0}
|
||||||
|
m_PrefabInternal: {fileID: 100100000}
|
||||||
|
serializedVersion: 4
|
||||||
|
m_Component:
|
||||||
|
- 4: {fileID: 400000}
|
||||||
|
- 143: {fileID: 14300000}
|
||||||
|
- 114: {fileID: 11400000}
|
||||||
|
- 54: {fileID: 5400000}
|
||||||
|
- 82: {fileID: 8200000}
|
||||||
|
m_Layer: 0
|
||||||
|
m_Name: FPSController
|
||||||
|
m_TagString: Untagged
|
||||||
|
m_Icon: {fileID: 0}
|
||||||
|
m_NavMeshLayer: 0
|
||||||
|
m_StaticEditorFlags: 0
|
||||||
|
m_IsActive: 1
|
||||||
|
--- !u!1 &100002
|
||||||
|
GameObject:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_PrefabParentObject: {fileID: 0}
|
||||||
|
m_PrefabInternal: {fileID: 100100000}
|
||||||
|
serializedVersion: 4
|
||||||
|
m_Component:
|
||||||
|
- 4: {fileID: 400002}
|
||||||
|
- 20: {fileID: 2000000}
|
||||||
|
- 81: {fileID: 8100000}
|
||||||
|
m_Layer: 0
|
||||||
|
m_Name: FirstPersonCharacter
|
||||||
|
m_TagString: MainCamera
|
||||||
|
m_Icon: {fileID: 0}
|
||||||
|
m_NavMeshLayer: 0
|
||||||
|
m_StaticEditorFlags: 0
|
||||||
|
m_IsActive: 1
|
||||||
|
--- !u!4 &400000
|
||||||
|
Transform:
|
||||||
|
m_ObjectHideFlags: 1
|
||||||
|
m_PrefabParentObject: {fileID: 0}
|
||||||
|
m_PrefabInternal: {fileID: 100100000}
|
||||||
|
m_GameObject: {fileID: 100000}
|
||||||
|
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||||
|
m_LocalPosition: {x: 140.699997, y: 12.8000002, z: -46.5}
|
||||||
|
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||||
|
m_Children:
|
||||||
|
- {fileID: 400002}
|
||||||
|
m_Father: {fileID: 0}
|
||||||
|
m_RootOrder: 0
|
||||||
|
--- !u!4 &400002
|
||||||
|
Transform:
|
||||||
|
m_ObjectHideFlags: 1
|
||||||
|
m_PrefabParentObject: {fileID: 0}
|
||||||
|
m_PrefabInternal: {fileID: 100100000}
|
||||||
|
m_GameObject: {fileID: 100002}
|
||||||
|
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||||
|
m_LocalPosition: {x: 0, y: .800000012, z: 0}
|
||||||
|
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||||
|
m_Children: []
|
||||||
|
m_Father: {fileID: 400000}
|
||||||
|
m_RootOrder: 0
|
||||||
|
--- !u!20 &2000000
|
||||||
|
Camera:
|
||||||
|
m_ObjectHideFlags: 1
|
||||||
|
m_PrefabParentObject: {fileID: 0}
|
||||||
|
m_PrefabInternal: {fileID: 100100000}
|
||||||
|
m_GameObject: {fileID: 100002}
|
||||||
|
m_Enabled: 1
|
||||||
|
serializedVersion: 2
|
||||||
|
m_ClearFlags: 1
|
||||||
|
m_BackGroundColor: {r: .192156866, g: .301960796, b: .474509805, a: .0196078438}
|
||||||
|
m_NormalizedViewPortRect:
|
||||||
|
serializedVersion: 2
|
||||||
|
x: 0
|
||||||
|
y: 0
|
||||||
|
width: 1
|
||||||
|
height: 1
|
||||||
|
near clip plane: .300000012
|
||||||
|
far clip plane: 1000
|
||||||
|
field of view: 60
|
||||||
|
orthographic: 0
|
||||||
|
orthographic size: 5
|
||||||
|
m_Depth: 0
|
||||||
|
m_CullingMask:
|
||||||
|
serializedVersion: 2
|
||||||
|
m_Bits: 4294967295
|
||||||
|
m_RenderingPath: -1
|
||||||
|
m_TargetTexture: {fileID: 0}
|
||||||
|
m_TargetDisplay: 0
|
||||||
|
m_HDR: 0
|
||||||
|
m_OcclusionCulling: 1
|
||||||
|
m_StereoConvergence: 10
|
||||||
|
m_StereoSeparation: .0219999999
|
||||||
|
--- !u!54 &5400000
|
||||||
|
Rigidbody:
|
||||||
|
m_ObjectHideFlags: 1
|
||||||
|
m_PrefabParentObject: {fileID: 0}
|
||||||
|
m_PrefabInternal: {fileID: 100100000}
|
||||||
|
m_GameObject: {fileID: 100000}
|
||||||
|
serializedVersion: 2
|
||||||
|
m_Mass: 1
|
||||||
|
m_Drag: 0
|
||||||
|
m_AngularDrag: .0500000007
|
||||||
|
m_UseGravity: 1
|
||||||
|
m_IsKinematic: 1
|
||||||
|
m_Interpolate: 0
|
||||||
|
m_Constraints: 0
|
||||||
|
m_CollisionDetection: 0
|
||||||
|
--- !u!81 &8100000
|
||||||
|
AudioListener:
|
||||||
|
m_ObjectHideFlags: 1
|
||||||
|
m_PrefabParentObject: {fileID: 0}
|
||||||
|
m_PrefabInternal: {fileID: 100100000}
|
||||||
|
m_GameObject: {fileID: 100002}
|
||||||
|
m_Enabled: 1
|
||||||
|
--- !u!82 &8200000
|
||||||
|
AudioSource:
|
||||||
|
m_ObjectHideFlags: 1
|
||||||
|
m_PrefabParentObject: {fileID: 0}
|
||||||
|
m_PrefabInternal: {fileID: 100100000}
|
||||||
|
m_GameObject: {fileID: 100000}
|
||||||
|
m_Enabled: 1
|
||||||
|
serializedVersion: 4
|
||||||
|
OutputAudioMixerGroup: {fileID: 0}
|
||||||
|
m_audioClip: {fileID: 0}
|
||||||
|
m_PlayOnAwake: 1
|
||||||
|
m_Volume: 1
|
||||||
|
m_Pitch: 1
|
||||||
|
Loop: 0
|
||||||
|
Mute: 0
|
||||||
|
Priority: 128
|
||||||
|
DopplerLevel: 1
|
||||||
|
MinDistance: 1
|
||||||
|
MaxDistance: 500
|
||||||
|
Pan2D: 0
|
||||||
|
rolloffMode: 0
|
||||||
|
BypassEffects: 0
|
||||||
|
BypassListenerEffects: 0
|
||||||
|
BypassReverbZones: 0
|
||||||
|
rolloffCustomCurve:
|
||||||
|
serializedVersion: 2
|
||||||
|
m_Curve:
|
||||||
|
- time: 0
|
||||||
|
value: 1
|
||||||
|
inSlope: 0
|
||||||
|
outSlope: 0
|
||||||
|
tangentMode: 0
|
||||||
|
- time: 1
|
||||||
|
value: 0
|
||||||
|
inSlope: 0
|
||||||
|
outSlope: 0
|
||||||
|
tangentMode: 0
|
||||||
|
m_PreInfinity: 2
|
||||||
|
m_PostInfinity: 2
|
||||||
|
panLevelCustomCurve:
|
||||||
|
serializedVersion: 2
|
||||||
|
m_Curve:
|
||||||
|
- time: 0
|
||||||
|
value: 1
|
||||||
|
inSlope: 0
|
||||||
|
outSlope: 0
|
||||||
|
tangentMode: 0
|
||||||
|
m_PreInfinity: 2
|
||||||
|
m_PostInfinity: 2
|
||||||
|
spreadCustomCurve:
|
||||||
|
serializedVersion: 2
|
||||||
|
m_Curve:
|
||||||
|
- time: 0
|
||||||
|
value: 0
|
||||||
|
inSlope: 0
|
||||||
|
outSlope: 0
|
||||||
|
tangentMode: 0
|
||||||
|
m_PreInfinity: 2
|
||||||
|
m_PostInfinity: 2
|
||||||
|
reverbZoneMixCustomCurve:
|
||||||
|
serializedVersion: 2
|
||||||
|
m_Curve:
|
||||||
|
- time: 0
|
||||||
|
value: 1
|
||||||
|
inSlope: 0
|
||||||
|
outSlope: 0
|
||||||
|
tangentMode: 0
|
||||||
|
m_PreInfinity: 2
|
||||||
|
m_PostInfinity: 2
|
||||||
|
--- !u!114 &11400000
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 1
|
||||||
|
m_PrefabParentObject: {fileID: 0}
|
||||||
|
m_PrefabInternal: {fileID: 100100000}
|
||||||
|
m_GameObject: {fileID: 100000}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: 05ec5cf00ca181d45a42ba1870e148c3, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
m_IsWalking: 0
|
||||||
|
m_WalkSpeed: 5
|
||||||
|
m_RunSpeed: 10
|
||||||
|
m_RunstepLenghten: .699999988
|
||||||
|
m_JumpSpeed: 10
|
||||||
|
m_StickToGroundForce: 10
|
||||||
|
m_GravityMultiplier: 2
|
||||||
|
m_MouseLook:
|
||||||
|
XSensitivity: 2
|
||||||
|
YSensitivity: 2
|
||||||
|
clampVerticalRotation: 1
|
||||||
|
MinimumX: -90
|
||||||
|
MaximumX: 90
|
||||||
|
smooth: 0
|
||||||
|
smoothTime: 5
|
||||||
|
m_UseFovKick: 1
|
||||||
|
m_FovKick:
|
||||||
|
Camera: {fileID: 0}
|
||||||
|
originalFov: 0
|
||||||
|
FOVIncrease: 3
|
||||||
|
TimeToIncrease: 1
|
||||||
|
TimeToDecrease: 1
|
||||||
|
IncreaseCurve:
|
||||||
|
serializedVersion: 2
|
||||||
|
m_Curve:
|
||||||
|
- time: 0
|
||||||
|
value: 0
|
||||||
|
inSlope: 0
|
||||||
|
outSlope: 0
|
||||||
|
tangentMode: 0
|
||||||
|
- time: 1
|
||||||
|
value: 1
|
||||||
|
inSlope: 2
|
||||||
|
outSlope: 2
|
||||||
|
tangentMode: 0
|
||||||
|
m_PreInfinity: 2
|
||||||
|
m_PostInfinity: 2
|
||||||
|
m_UseHeadBob: 1
|
||||||
|
m_HeadBob:
|
||||||
|
HorizontalBobRange: .100000001
|
||||||
|
VerticalBobRange: .100000001
|
||||||
|
Bobcurve:
|
||||||
|
serializedVersion: 2
|
||||||
|
m_Curve:
|
||||||
|
- time: 0
|
||||||
|
value: 0
|
||||||
|
inSlope: 0
|
||||||
|
outSlope: 0
|
||||||
|
tangentMode: 0
|
||||||
|
- time: .5
|
||||||
|
value: 1
|
||||||
|
inSlope: 0
|
||||||
|
outSlope: 0
|
||||||
|
tangentMode: 0
|
||||||
|
- time: 1
|
||||||
|
value: 0
|
||||||
|
inSlope: 0
|
||||||
|
outSlope: 0
|
||||||
|
tangentMode: 0
|
||||||
|
- time: 1.5
|
||||||
|
value: -1
|
||||||
|
inSlope: 0
|
||||||
|
outSlope: 0
|
||||||
|
tangentMode: 0
|
||||||
|
- time: 2
|
||||||
|
value: 0
|
||||||
|
inSlope: 0
|
||||||
|
outSlope: 0
|
||||||
|
tangentMode: 0
|
||||||
|
m_PreInfinity: 2
|
||||||
|
m_PostInfinity: 2
|
||||||
|
VerticaltoHorizontalRatio: 2
|
||||||
|
m_JumpBob:
|
||||||
|
BobDuration: .200000003
|
||||||
|
BobAmount: .100000001
|
||||||
|
m_StepInterval: 5
|
||||||
|
m_FootstepSounds:
|
||||||
|
- {fileID: 8300000, guid: 42e65e088b3f4374e851b8dbd38f3df9, type: 3}
|
||||||
|
- {fileID: 8300000, guid: 8bc94ec6ed537e743b481638bdcd503d, type: 3}
|
||||||
|
m_JumpSound: {fileID: 8300000, guid: 5897aeed9b676024fbb8c694b421a861, type: 3}
|
||||||
|
m_LandSound: {fileID: 8300000, guid: 3b09d59f4499d45428baa7a21e954296, type: 3}
|
||||||
|
--- !u!143 &14300000
|
||||||
|
CharacterController:
|
||||||
|
m_ObjectHideFlags: 1
|
||||||
|
m_PrefabParentObject: {fileID: 0}
|
||||||
|
m_PrefabInternal: {fileID: 100100000}
|
||||||
|
m_GameObject: {fileID: 100000}
|
||||||
|
m_Material: {fileID: 0}
|
||||||
|
m_IsTrigger: 0
|
||||||
|
m_Enabled: 1
|
||||||
|
serializedVersion: 2
|
||||||
|
m_Height: 1.79999995
|
||||||
|
m_Radius: .5
|
||||||
|
m_SlopeLimit: 45
|
||||||
|
m_StepOffset: .300000012
|
||||||
|
m_SkinWidth: .0799999982
|
||||||
|
m_MinMoveDistance: 0
|
||||||
|
m_Center: {x: 0, y: 0, z: 0}
|
||||||
|
--- !u!1001 &100100000
|
||||||
|
Prefab:
|
||||||
|
m_ObjectHideFlags: 1
|
||||||
|
serializedVersion: 2
|
||||||
|
m_Modification:
|
||||||
|
m_TransformParent: {fileID: 0}
|
||||||
|
m_Modifications: []
|
||||||
|
m_RemovedComponents: []
|
||||||
|
m_ParentPrefab: {fileID: 0}
|
||||||
|
m_RootGameObject: {fileID: 100000}
|
||||||
|
m_IsPrefabParent: 1
|
||||||
@ -0,0 +1,5 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 5e9e851c0e142814dac026a256ba2ac0
|
||||||
|
NativeFormatImporter:
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
@ -0,0 +1,257 @@
|
|||||||
|
using System;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityStandardAssets.CrossPlatformInput;
|
||||||
|
using UnityStandardAssets.Utility;
|
||||||
|
using Random = UnityEngine.Random;
|
||||||
|
|
||||||
|
namespace UnityStandardAssets.Characters.FirstPerson
|
||||||
|
{
|
||||||
|
[RequireComponent(typeof (CharacterController))]
|
||||||
|
[RequireComponent(typeof (AudioSource))]
|
||||||
|
public class FirstPersonController : MonoBehaviour
|
||||||
|
{
|
||||||
|
[SerializeField] private bool m_IsWalking;
|
||||||
|
[SerializeField] private float m_WalkSpeed;
|
||||||
|
[SerializeField] private float m_RunSpeed;
|
||||||
|
[SerializeField] [Range(0f, 1f)] private float m_RunstepLenghten;
|
||||||
|
[SerializeField] private float m_JumpSpeed;
|
||||||
|
[SerializeField] private float m_StickToGroundForce;
|
||||||
|
[SerializeField] private float m_GravityMultiplier;
|
||||||
|
[SerializeField] private MouseLook m_MouseLook;
|
||||||
|
[SerializeField] private bool m_UseFovKick;
|
||||||
|
[SerializeField] private FOVKick m_FovKick = new FOVKick();
|
||||||
|
[SerializeField] private bool m_UseHeadBob;
|
||||||
|
[SerializeField] private CurveControlledBob m_HeadBob = new CurveControlledBob();
|
||||||
|
[SerializeField] private LerpControlledBob m_JumpBob = new LerpControlledBob();
|
||||||
|
[SerializeField] private float m_StepInterval;
|
||||||
|
[SerializeField] private AudioClip[] m_FootstepSounds; // an array of footstep sounds that will be randomly selected from.
|
||||||
|
[SerializeField] private AudioClip m_JumpSound; // the sound played when character leaves the ground.
|
||||||
|
[SerializeField] private AudioClip m_LandSound; // the sound played when character touches back on ground.
|
||||||
|
|
||||||
|
private Camera m_Camera;
|
||||||
|
private bool m_Jump;
|
||||||
|
private float m_YRotation;
|
||||||
|
private Vector2 m_Input;
|
||||||
|
private Vector3 m_MoveDir = Vector3.zero;
|
||||||
|
private CharacterController m_CharacterController;
|
||||||
|
private CollisionFlags m_CollisionFlags;
|
||||||
|
private bool m_PreviouslyGrounded;
|
||||||
|
private Vector3 m_OriginalCameraPosition;
|
||||||
|
private float m_StepCycle;
|
||||||
|
private float m_NextStep;
|
||||||
|
private bool m_Jumping;
|
||||||
|
private AudioSource m_AudioSource;
|
||||||
|
|
||||||
|
// Use this for initialization
|
||||||
|
private void Start()
|
||||||
|
{
|
||||||
|
m_CharacterController = GetComponent<CharacterController>();
|
||||||
|
m_Camera = Camera.main;
|
||||||
|
m_OriginalCameraPosition = m_Camera.transform.localPosition;
|
||||||
|
m_FovKick.Setup(m_Camera);
|
||||||
|
m_HeadBob.Setup(m_Camera, m_StepInterval);
|
||||||
|
m_StepCycle = 0f;
|
||||||
|
m_NextStep = m_StepCycle/2f;
|
||||||
|
m_Jumping = false;
|
||||||
|
m_AudioSource = GetComponent<AudioSource>();
|
||||||
|
m_MouseLook.Init(transform , m_Camera.transform);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Update is called once per frame
|
||||||
|
private void Update()
|
||||||
|
{
|
||||||
|
RotateView();
|
||||||
|
// the jump state needs to read here to make sure it is not missed
|
||||||
|
if (!m_Jump)
|
||||||
|
{
|
||||||
|
m_Jump = CrossPlatformInputManager.GetButtonDown("Jump");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!m_PreviouslyGrounded && m_CharacterController.isGrounded)
|
||||||
|
{
|
||||||
|
StartCoroutine(m_JumpBob.DoBobCycle());
|
||||||
|
PlayLandingSound();
|
||||||
|
m_MoveDir.y = 0f;
|
||||||
|
m_Jumping = false;
|
||||||
|
}
|
||||||
|
if (!m_CharacterController.isGrounded && !m_Jumping && m_PreviouslyGrounded)
|
||||||
|
{
|
||||||
|
m_MoveDir.y = 0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_PreviouslyGrounded = m_CharacterController.isGrounded;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void PlayLandingSound()
|
||||||
|
{
|
||||||
|
m_AudioSource.clip = m_LandSound;
|
||||||
|
m_AudioSource.Play();
|
||||||
|
m_NextStep = m_StepCycle + .5f;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void FixedUpdate()
|
||||||
|
{
|
||||||
|
float speed;
|
||||||
|
GetInput(out speed);
|
||||||
|
// always move along the camera forward as it is the direction that it being aimed at
|
||||||
|
Vector3 desiredMove = transform.forward*m_Input.y + transform.right*m_Input.x;
|
||||||
|
|
||||||
|
// get a normal for the surface that is being touched to move along it
|
||||||
|
RaycastHit hitInfo;
|
||||||
|
Physics.SphereCast(transform.position, m_CharacterController.radius, Vector3.down, out hitInfo,
|
||||||
|
m_CharacterController.height/2f);
|
||||||
|
desiredMove = Vector3.ProjectOnPlane(desiredMove, hitInfo.normal).normalized;
|
||||||
|
|
||||||
|
m_MoveDir.x = desiredMove.x*speed;
|
||||||
|
m_MoveDir.z = desiredMove.z*speed;
|
||||||
|
|
||||||
|
|
||||||
|
if (m_CharacterController.isGrounded)
|
||||||
|
{
|
||||||
|
m_MoveDir.y = -m_StickToGroundForce;
|
||||||
|
|
||||||
|
if (m_Jump)
|
||||||
|
{
|
||||||
|
m_MoveDir.y = m_JumpSpeed;
|
||||||
|
PlayJumpSound();
|
||||||
|
m_Jump = false;
|
||||||
|
m_Jumping = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_MoveDir += Physics.gravity*m_GravityMultiplier*Time.fixedDeltaTime;
|
||||||
|
}
|
||||||
|
m_CollisionFlags = m_CharacterController.Move(m_MoveDir*Time.fixedDeltaTime);
|
||||||
|
|
||||||
|
ProgressStepCycle(speed);
|
||||||
|
UpdateCameraPosition(speed);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void PlayJumpSound()
|
||||||
|
{
|
||||||
|
m_AudioSource.clip = m_JumpSound;
|
||||||
|
m_AudioSource.Play();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void ProgressStepCycle(float speed)
|
||||||
|
{
|
||||||
|
if (m_CharacterController.velocity.sqrMagnitude > 0 && (m_Input.x != 0 || m_Input.y != 0))
|
||||||
|
{
|
||||||
|
m_StepCycle += (m_CharacterController.velocity.magnitude + (speed*(m_IsWalking ? 1f : m_RunstepLenghten)))*
|
||||||
|
Time.fixedDeltaTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(m_StepCycle > m_NextStep))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_NextStep = m_StepCycle + m_StepInterval;
|
||||||
|
|
||||||
|
PlayFootStepAudio();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void PlayFootStepAudio()
|
||||||
|
{
|
||||||
|
if (!m_CharacterController.isGrounded)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// pick & play a random footstep sound from the array,
|
||||||
|
// excluding sound at index 0
|
||||||
|
int n = Random.Range(1, m_FootstepSounds.Length);
|
||||||
|
m_AudioSource.clip = m_FootstepSounds[n];
|
||||||
|
m_AudioSource.PlayOneShot(m_AudioSource.clip);
|
||||||
|
// move picked sound to index 0 so it's not picked next time
|
||||||
|
m_FootstepSounds[n] = m_FootstepSounds[0];
|
||||||
|
m_FootstepSounds[0] = m_AudioSource.clip;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void UpdateCameraPosition(float speed)
|
||||||
|
{
|
||||||
|
Vector3 newCameraPosition;
|
||||||
|
if (!m_UseHeadBob)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (m_CharacterController.velocity.magnitude > 0 && m_CharacterController.isGrounded)
|
||||||
|
{
|
||||||
|
m_Camera.transform.localPosition =
|
||||||
|
m_HeadBob.DoHeadBob(m_CharacterController.velocity.magnitude +
|
||||||
|
(speed*(m_IsWalking ? 1f : m_RunstepLenghten)));
|
||||||
|
newCameraPosition = m_Camera.transform.localPosition;
|
||||||
|
newCameraPosition.y = m_Camera.transform.localPosition.y - m_JumpBob.Offset();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
newCameraPosition = m_Camera.transform.localPosition;
|
||||||
|
newCameraPosition.y = m_OriginalCameraPosition.y - m_JumpBob.Offset();
|
||||||
|
}
|
||||||
|
m_Camera.transform.localPosition = newCameraPosition;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void GetInput(out float speed)
|
||||||
|
{
|
||||||
|
// Read input
|
||||||
|
float horizontal = CrossPlatformInputManager.GetAxis("Horizontal");
|
||||||
|
float vertical = CrossPlatformInputManager.GetAxis("Vertical");
|
||||||
|
|
||||||
|
bool waswalking = m_IsWalking;
|
||||||
|
|
||||||
|
#if !MOBILE_INPUT
|
||||||
|
// On standalone builds, walk/run speed is modified by a key press.
|
||||||
|
// keep track of whether or not the character is walking or running
|
||||||
|
m_IsWalking = !Input.GetKey(KeyCode.LeftShift);
|
||||||
|
#endif
|
||||||
|
// set the desired speed to be walking or running
|
||||||
|
speed = m_IsWalking ? m_WalkSpeed : m_RunSpeed;
|
||||||
|
m_Input = new Vector2(horizontal, vertical);
|
||||||
|
|
||||||
|
// normalize input if it exceeds 1 in combined length:
|
||||||
|
if (m_Input.sqrMagnitude > 1)
|
||||||
|
{
|
||||||
|
m_Input.Normalize();
|
||||||
|
}
|
||||||
|
|
||||||
|
// handle speed change to give an fov kick
|
||||||
|
// only if the player is going to a run, is running and the fovkick is to be used
|
||||||
|
if (m_IsWalking != waswalking && m_UseFovKick && m_CharacterController.velocity.sqrMagnitude > 0)
|
||||||
|
{
|
||||||
|
StopAllCoroutines();
|
||||||
|
StartCoroutine(!m_IsWalking ? m_FovKick.FOVKickUp() : m_FovKick.FOVKickDown());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void RotateView()
|
||||||
|
{
|
||||||
|
m_MouseLook.LookRotation (transform, m_Camera.transform);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void OnControllerColliderHit(ControllerColliderHit hit)
|
||||||
|
{
|
||||||
|
Rigidbody body = hit.collider.attachedRigidbody;
|
||||||
|
//dont move the rigidbody if the character is on top of it
|
||||||
|
if (m_CollisionFlags == CollisionFlags.Below)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (body == null || body.isKinematic)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
body.AddForceAtPosition(m_CharacterController.velocity*0.1f, hit.point, ForceMode.Impulse);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,9 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 05ec5cf00ca181d45a42ba1870e148c3
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
7
Assets/Standard Assets/Characters/PhysicsMaterials.meta
Normal file
7
Assets/Standard Assets/Characters/PhysicsMaterials.meta
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: ea2a5216ffb8d4b319d09e8d7782120c
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
Loading…
x
Reference in New Issue
Block a user