Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
c5cd2f9
Inner double quote is romved from subtitles
imrankhanswati Aug 26, 2016
841690a
Player can only complet by geting and call, also scrtch sound is fixe…
imrankhanswati Aug 26, 2016
e663adb
Exit button is added to menu and faze trough reck is removed
imrankhanswati Aug 29, 2016
2a1f27d
Light pass under wall is fixed
imrankhanswati Aug 30, 2016
65a25eb
phone sound got fixed
imrankhanswati Aug 31, 2016
b354dcb
Light through wall is fixed
imrankhanswati Sep 1, 2016
b9e33f5
textures in light is fixed
imrankhanswati Sep 1, 2016
30f9a30
light is recoverd
imrankhanswati Sep 1, 2016
7edd9b4
Light flow through wall is fixed
imrankhanswati Sep 1, 2016
7a3e9c2
Light tweeking is removed
imrankhanswati Sep 2, 2016
b8e9bc9
material fixed
imrankhanswati Sep 2, 2016
f6b189c
character controller is added to player
imrankhanswati Sep 5, 2016
5841fc5
Light is fixed
imrankhanswati Sep 6, 2016
4c20bb1
player movement got fixed
imrankhanswati Sep 7, 2016
2dbc01c
player interaction with environment id don and occlusion culling is don
imrankhanswati Sep 8, 2016
d824e8f
Path finding is added to ghosts
imrankhanswati Sep 9, 2016
15f61d4
Code is optimized
imrankhanswati Sep 19, 2016
3bf39d7
First Person View is added
imrankhanswati Sep 20, 2016
5c27017
limits for camera got fixed
imrankhanswati Sep 20, 2016
42f87e0
Door opening is converted from animation to script and light cookie i…
imrankhanswati Sep 22, 2016
38bc960
Door models is optimization and textures is added to doors
imrankhanswati Sep 23, 2016
0af32dc
Door open scrip is updated
imrankhanswati Sep 26, 2016
78798c0
Helper is added
imrankhanswati Sep 26, 2016
c12d8dd
Faze through door is removed
imrankhanswati Sep 26, 2016
e55f6a9
fixed conflicts
imrankhanswati Sep 27, 2016
4a3358e
Graphics Optimized
imrankhanswati Sep 29, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Binary file modified Assets/Animator/Character.controller
Binary file not shown.
286 changes: 286 additions & 0 deletions Assets/ChrecterController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,286 @@
using UnityEngine;
using System.Collections;
using UnityStandardAssets.CrossPlatformInput;
using UnityStandardAssets.Characters.FirstPerson;
using UnityStandardAssets.Utility;

public class ChrecterController : MonoBehaviour {
//public float speed = 6.0F;
//public float jumpSpeed = 8.0F;
//public float gravity = 20.0F;
//private Vector3 moveDirection = Vector3.zero;

//void Update()
//{
// CharacterController controller = GetComponent<CharacterController>();
// if (controller.isGrounded)
// {
// if (PlayerMovement.playerDirection == PlayerDirection.FORWARD)
// {
// moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
// }
// else
// {
// moveDirection = new Vector3(-(Input.GetAxis("Horizontal")), 0, Input.GetAxis("Vertical"));
// }
// moveDirection = transform.TransformDirection(moveDirection);
// moveDirection *= speed;
// }
// moveDirection.y -= gravity * Time.deltaTime;
// controller.Move(moveDirection * Time.deltaTime);
//}
//Debug.Log("controller");

[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.
[SerializeField] private float m_minXRot;
[SerializeField] private float m_maxXRot;

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, Physics.AllLayers, QueryTriggerInteraction.Ignore);
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);
if (m_Camera.transform.rotation.eulerAngles.x > m_minXRot && m_Camera.transform.rotation.eulerAngles.x < m_maxXRot)
{
UpdateCameraPosition(speed);

}
m_MouseLook.UpdateCursorLock();
}


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);
}
}


12 changes: 12 additions & 0 deletions Assets/ChrecterController.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading