Skip to content

Commit fdbfe31

Browse files
Leaning Mechanic (WIP)
Date Modified: 5/5/2017 @ 11:28 pm Changelog: Added the beginnings of the PlayerLean() function. Was working fine before, need to work out the glitches now. Unity says that you can't have multiple transforms in the Debug Console, or something of the sort when I run the program and press 'q' or 'e' (Leaning Mechanic).
1 parent 3f7b5b5 commit fdbfe31

2 files changed

Lines changed: 37 additions & 23 deletions

File tree

CSClub2017/CSClub 2017/Assets/Scripts/PlayerControl.cs

Lines changed: 37 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
*
33
* Author: Spencer Wilson
4-
* Date: 3/14/2017 (Happy Pi-Day everyone!)
4+
* Date: 5/5/2017, 11:28 pm
55
* File: PlayerControl.cs
66
* Description: This file contains the code that takes user input in order to control the character.
77
* Disclaimer: A majority of this code I have gotten from tutorials. I have not been simply copying them, I have been
@@ -62,10 +62,10 @@ private void Update()
6262
void FixedUpdate() // Used a tutorial, hopefully going to be expanding on this method to suit the game's needs and functionalities.
6363
{
6464
PlayerRotation(); // Calls upon the PlayerRotation() function.
65-
//PlayerRun(); // Calls upon the PlayerRun() function.
65+
PlayerRun(); // Calls upon the PlayerRun() function.
6666
PlayerMovement(); // Calls upon the PlayerMovement() function.
6767
//PlayerCrouch(); // Calls upon the PlayerCrouch() function.
68-
//PlayerLean(); // Calls upon the PlayerLean() function.
68+
PlayerLean(); // Calls upon the PlayerLean() function.
6969
//PlayerProne(); // Calls upon the PlayerProne() function.
7070
PlayerPause();
7171
}
@@ -192,27 +192,41 @@ void PlayerCrouch()
192192

193193

194194

195-
void PlayerLean()
196-
{
197-
if (Input.GetKeyDown("q"))
198-
{
199-
// Insert Lean Left Code Here
200-
}
201-
if (Input.GetKeyUp("q"))
202-
{
203-
// Insert Return To Normal Posture Code Here
204-
}
205-
if (Input.GetKeyDown("e"))
206-
{
207-
// Insert Lean Right Code Here
208-
}
209-
if (Input.GetKeyUp("e"))
210-
{
211-
// Insert Return To Normal Posture Code Here
212-
}
213-
}
195+
void PlayerLean()
196+
{
197+
float zRotation = 10f; // Holds value for rotation along the z-axis.
198+
float yRotation = 0; // Holds value for rotation along the y-axis.
199+
const float MAXZROTATION = (3f * Mathf.PI) / 2f;
200+
const float MINZROTATION = (Mathf.PI) / 4f;
201+
float newXRotation;
202+
203+
if (Input.GetKeyDown("q"))
204+
{
205+
Debug.Log("Lean Left");
206+
transform.localEulerAngles = new Vector3(0f, 0f, zRotation);
207+
// Mathf.Clamp(zRotation, MINZROTATION, MAXZROTATION); // Clamps rotation between two values to give a realistic range of leaning.
208+
}
209+
if (Input.GetKeyUp("q"))
210+
{
211+
Debug.Log("Upright position");
212+
transform.localEulerAngles = new Vector3(0f, 0f, 0f);
213+
// Mathf.Clamp(zRotation, MINZROTATION, MAXZROTATION); // Clamps rotation between two values to give a realistic range of leaning.
214+
}
215+
if (Input.GetKeyDown("e"))
216+
{
217+
Debug.Log("Lean Right");
218+
transform.localEulerAngles = new Vector3(0f, 0f, -zRotation);
219+
// Mathf.Clamp(zRotation, MINZROTATION, MAXZROTATION); // Clamps rotation between two values to give a realistic range of leaning.
220+
}
221+
if (Input.GetKeyUp("e"))
222+
{
223+
Debug.Log("Upright position");
224+
transform.localEulerAngles = new Vector3(0f, 0f, 0f);
225+
// Mathf.Clamp(zRotation, MINZROTATION, MAXZROTATION); // Clamps rotation between two values to give a realistic range of leaning.
226+
}
227+
}
214228

215-
void PlayerProne()
229+
void PlayerProne()
216230
{
217231
// Insert Player Prone Stuff. Might have to call upon the PlayerMovement function here to change the value of speed so it is slower when crawling.
218232
}
588 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)