Merge branch 'master' of https://gitlab.nicholasnovak.io/fums/ofb
This commit is contained in:
commit
f1844faea3
@ -116,223 +116,227 @@ public class PlayerMovement : MonoBehaviour
|
|||||||
FreezeControl();
|
FreezeControl();
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
|
|
||||||
if(isFrozen)
|
if(isFrozen)
|
||||||
{
|
|
||||||
Data.gravityStrength = tempGrav;
|
|
||||||
Data.fallGravityMult = tempFall;
|
|
||||||
isFrozen = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
unlockedTrumpet = stateController.unlockedTrumpet;
|
|
||||||
#region TIMERS
|
|
||||||
LastOnGroundTime -= Time.deltaTime;
|
|
||||||
LastOnWallTime -= Time.deltaTime;
|
|
||||||
LastOnWallRightTime -= Time.deltaTime;
|
|
||||||
LastOnWallLeftTime -= Time.deltaTime;
|
|
||||||
|
|
||||||
LastPressedJumpTime -= Time.deltaTime;
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region INPUT HANDLER
|
|
||||||
|
|
||||||
if (_moveInput.x != 0)
|
|
||||||
CheckDirectionToFace(_moveInput.x > 0);
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
// if (!IsJumping)
|
|
||||||
// {
|
|
||||||
// print("not jumping");
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
// {
|
|
||||||
// print("jumping, " + RB.velocity.y);
|
|
||||||
// }
|
|
||||||
|
|
||||||
#region COLLISION CHECKS
|
|
||||||
if (!IsJumping)
|
|
||||||
{
|
|
||||||
//Ground Check
|
|
||||||
if (IsGrounded()) //checks if set box overlaps with ground
|
|
||||||
{
|
{
|
||||||
LastOnGroundTime = Data.coyoteTime; //if so sets the lastGrounded to coyoteTime
|
Data.gravityStrength = tempGrav;
|
||||||
if (unlockedTrumpet) {
|
Data.fallGravityMult = tempFall;
|
||||||
trumpet = 2;
|
isFrozen = false;
|
||||||
gameUI.ToggleTrumpet(true);
|
}
|
||||||
} else {
|
|
||||||
trumpet = -1;
|
unlockedTrumpet = stateController.unlockedTrumpet;
|
||||||
}
|
#region TIMERS
|
||||||
wasGrappling = false;
|
LastOnGroundTime -= Time.deltaTime;
|
||||||
isRegFalling = false;
|
LastOnWallTime -= Time.deltaTime;
|
||||||
} else {
|
LastOnWallRightTime -= Time.deltaTime;
|
||||||
// print("not jumping");
|
LastOnWallLeftTime -= Time.deltaTime;
|
||||||
if(!_isJumpFalling && !isRegFalling) {
|
|
||||||
if(unlockedTrumpet) {
|
LastPressedJumpTime -= Time.deltaTime;
|
||||||
trumpet = 1;
|
#endregion
|
||||||
|
|
||||||
|
#region INPUT HANDLER
|
||||||
|
|
||||||
|
if (_moveInput.x != 0)
|
||||||
|
CheckDirectionToFace(_moveInput.x > 0);
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
// if (!IsJumping)
|
||||||
|
// {
|
||||||
|
// print("not jumping");
|
||||||
|
// }
|
||||||
|
// else
|
||||||
|
// {
|
||||||
|
// print("jumping, " + RB.velocity.y);
|
||||||
|
// }
|
||||||
|
|
||||||
|
#region COLLISION CHECKS
|
||||||
|
if (!IsJumping)
|
||||||
|
{
|
||||||
|
//Ground Check
|
||||||
|
if (IsGrounded()) //checks if set box overlaps with ground
|
||||||
|
{
|
||||||
|
LastOnGroundTime = Data.coyoteTime; //if so sets the lastGrounded to coyoteTime
|
||||||
|
if (unlockedTrumpet) {
|
||||||
|
trumpet = 2;
|
||||||
gameUI.ToggleTrumpet(true);
|
gameUI.ToggleTrumpet(true);
|
||||||
} else {
|
} else {
|
||||||
trumpet = -1;
|
trumpet = -1;
|
||||||
}
|
}
|
||||||
isRegFalling = true;
|
wasGrappling = false;
|
||||||
|
isRegFalling = false;
|
||||||
|
} else {
|
||||||
|
// print("not jumping");
|
||||||
|
if(!_isJumpFalling && !isRegFalling) {
|
||||||
|
if(unlockedTrumpet) {
|
||||||
|
trumpet = 1;
|
||||||
|
gameUI.ToggleTrumpet(true);
|
||||||
|
} else {
|
||||||
|
trumpet = -1;
|
||||||
|
}
|
||||||
|
isRegFalling = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Right Wall Check
|
||||||
|
if (((Physics2D.OverlapBox(this.transform.position, _wallCheckSize, 0, _groundLayer) && IsFacingRight)
|
||||||
|
|| (Physics2D.OverlapBox(this.transform.position, _wallCheckSize, 0, _groundLayer) && !IsFacingRight)) && !IsWallJumping)
|
||||||
|
LastOnWallRightTime = Data.coyoteTime;
|
||||||
|
|
||||||
|
//Right Wall Check
|
||||||
|
if (((Physics2D.OverlapBox(this.transform.position, _wallCheckSize, 0, _groundLayer) && !IsFacingRight)
|
||||||
|
|| (Physics2D.OverlapBox(this.transform.position, _wallCheckSize, 0, _groundLayer) && IsFacingRight)) && !IsWallJumping)
|
||||||
|
LastOnWallLeftTime = Data.coyoteTime;
|
||||||
|
|
||||||
|
//Two checks needed for both left and right walls since whenever the play turns the wall checkPoints swap sides
|
||||||
|
LastOnWallTime = Mathf.Max(LastOnWallLeftTime, LastOnWallRightTime);
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region JUMP CHECKS
|
||||||
|
if (IsJumping && RB.velocity.y <= 0)
|
||||||
|
{
|
||||||
|
IsJumping = false;
|
||||||
|
// print("isJumping " + IsJumping);
|
||||||
|
|
||||||
|
if (!IsWallJumping)
|
||||||
|
_isJumpFalling = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (IsWallJumping && Time.time - _wallJumpStartTime > Data.wallJumpTime)
|
||||||
|
{
|
||||||
|
IsWallJumping = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (LastOnGroundTime > 0 && !IsJumping && !IsWallJumping)
|
||||||
|
{
|
||||||
|
_isJumpCut = false;
|
||||||
|
|
||||||
|
if (!IsJumping)
|
||||||
|
_isJumpFalling = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Jump
|
||||||
|
if (CanJump() && LastPressedJumpTime > 0)
|
||||||
|
{
|
||||||
|
IsJumping = true;
|
||||||
|
IsWallJumping = false;
|
||||||
|
_isJumpCut = false;
|
||||||
|
_isJumpFalling = false;
|
||||||
|
Jump();
|
||||||
|
|
||||||
|
if (!IsGrounded() && in_range && trumpet > 0)
|
||||||
|
{
|
||||||
|
gameObject.transform.Find("Trumpet").GetComponent<AudioSource>().Play();
|
||||||
|
enemy.GetComponent<EnemyPatrol>().DefeatEnemy();
|
||||||
|
enemy = null;
|
||||||
|
in_range = false;
|
||||||
|
}
|
||||||
|
else if (!IsGrounded() && !in_range && trumpet > 0)
|
||||||
|
{
|
||||||
|
trumpet -= 1;
|
||||||
|
}
|
||||||
|
// check if double jump, play sound
|
||||||
|
if (trumpet == 0) {
|
||||||
|
gameObject.transform.Find("Trumpet").GetComponent<AudioSource>().Play();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Right Wall Check
|
// stop sound if needed
|
||||||
if (((Physics2D.OverlapBox(this.transform.position, _wallCheckSize, 0, _groundLayer) && IsFacingRight)
|
if (soundPlaying && (isRegFalling || IsJumping || _isJumpFalling)) {
|
||||||
|| (Physics2D.OverlapBox(this.transform.position, _wallCheckSize, 0, _groundLayer) && !IsFacingRight)) && !IsWallJumping)
|
print("footsteps stop");
|
||||||
LastOnWallRightTime = Data.coyoteTime;
|
audioSource.Stop();
|
||||||
|
soundPlaying = false;
|
||||||
//Right Wall Check
|
|
||||||
if (((Physics2D.OverlapBox(this.transform.position, _wallCheckSize, 0, _groundLayer) && !IsFacingRight)
|
|
||||||
|| (Physics2D.OverlapBox(this.transform.position, _wallCheckSize, 0, _groundLayer) && IsFacingRight)) && !IsWallJumping)
|
|
||||||
LastOnWallLeftTime = Data.coyoteTime;
|
|
||||||
|
|
||||||
//Two checks needed for both left and right walls since whenever the play turns the wall checkPoints swap sides
|
|
||||||
LastOnWallTime = Mathf.Max(LastOnWallLeftTime, LastOnWallRightTime);
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region JUMP CHECKS
|
|
||||||
if (IsJumping && RB.velocity.y <= 0)
|
|
||||||
{
|
|
||||||
IsJumping = false;
|
|
||||||
// print("isJumping " + IsJumping);
|
|
||||||
|
|
||||||
if (!IsWallJumping)
|
|
||||||
_isJumpFalling = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (IsWallJumping && Time.time - _wallJumpStartTime > Data.wallJumpTime)
|
|
||||||
{
|
|
||||||
IsWallJumping = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (LastOnGroundTime > 0 && !IsJumping && !IsWallJumping)
|
|
||||||
{
|
|
||||||
_isJumpCut = false;
|
|
||||||
|
|
||||||
if (!IsJumping)
|
|
||||||
_isJumpFalling = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Jump
|
|
||||||
if (CanJump() && LastPressedJumpTime > 0)
|
|
||||||
{
|
|
||||||
IsJumping = true;
|
|
||||||
IsWallJumping = false;
|
|
||||||
_isJumpCut = false;
|
|
||||||
_isJumpFalling = false;
|
|
||||||
Jump();
|
|
||||||
|
|
||||||
if (!IsGrounded() && in_range && trumpet > 0)
|
|
||||||
{
|
|
||||||
gameObject.transform.Find("Trumpet").GetComponent<AudioSource>().Play();
|
|
||||||
enemy.GetComponent<EnemyPatrol>().DefeatEnemy();
|
|
||||||
enemy = null;
|
|
||||||
in_range = false;
|
|
||||||
}
|
}
|
||||||
else if (!IsGrounded() && !in_range && trumpet > 0)
|
|
||||||
{
|
//WALL JUMP
|
||||||
trumpet -= 1;
|
// else if (CanWallJump() && LastPressedJumpTime > 0)
|
||||||
|
// {
|
||||||
|
// IsWallJumping = true;
|
||||||
|
// IsJumping = false;
|
||||||
|
// _isJumpCut = false;
|
||||||
|
// _isJumpFalling = false;
|
||||||
|
// _wallJumpStartTime = Time.time;
|
||||||
|
// _lastWallJumpDir = (LastOnWallRightTime > 0) ? -1 : 1;
|
||||||
|
//
|
||||||
|
// WallJump(_lastWallJumpDir);
|
||||||
|
// }
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region GRAPPLE CHECKS
|
||||||
|
// set wasGrappling to true if the player starts grappling
|
||||||
|
if (grapplingRope.isGrappling) {
|
||||||
|
wasGrappling = true;
|
||||||
}
|
}
|
||||||
// check if double jump, play sound
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
#region SLIDE CHECKS
|
||||||
|
if (CanSlide() && ((LastOnWallLeftTime > 0 && _moveInput.x < 0) || (LastOnWallRightTime > 0 && _moveInput.x > 0)))
|
||||||
|
IsSliding = true;
|
||||||
|
else
|
||||||
|
IsSliding = false;
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region GRAVITY
|
||||||
|
//Higher gravity if we've released the jump input or are falling
|
||||||
|
if (IsSliding)
|
||||||
|
{
|
||||||
|
SetGravityScale(0);
|
||||||
|
}
|
||||||
|
else if (RB.velocity.y < 0 && _moveInput.y < 0)
|
||||||
|
{
|
||||||
|
//Much higher gravity if holding down
|
||||||
|
SetGravityScale(Data.gravityScale * Data.fastFallGravityMult);
|
||||||
|
//Caps maximum fall speed, so when falling over large distances we don't accelerate to insanely high speeds
|
||||||
|
RB.velocity = new Vector2(RB.velocity.x, Mathf.Max(RB.velocity.y, -Data.maxFastFallSpeed));
|
||||||
|
}
|
||||||
|
else if (_isJumpCut)
|
||||||
|
{
|
||||||
|
//Higher gravity if jump button released
|
||||||
|
SetGravityScale(Data.gravityScale * Data.jumpCutGravityMult);
|
||||||
|
RB.velocity = new Vector2(RB.velocity.x, Mathf.Max(RB.velocity.y, -Data.maxFallSpeed));
|
||||||
|
}
|
||||||
|
else if ((IsJumping || IsWallJumping || _isJumpFalling) && Mathf.Abs(RB.velocity.y) < Data.jumpHangTimeThreshold)
|
||||||
|
{
|
||||||
|
SetGravityScale(Data.gravityScale * Data.jumpHangGravityMult);
|
||||||
|
}
|
||||||
|
else if (RB.velocity.y < 0)
|
||||||
|
{
|
||||||
|
//Higher gravity if falling
|
||||||
|
SetGravityScale(Data.gravityScale * Data.fallGravityMult);
|
||||||
|
//Caps maximum fall speed, so when falling over large distances we don't accelerate to insanely high speeds
|
||||||
|
RB.velocity = new Vector2(RB.velocity.x, Mathf.Max(RB.velocity.y, -Data.maxFallSpeed));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//Default gravity if standing on a platform or moving upwards
|
||||||
|
SetGravityScale(Data.gravityScale);
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region SOUND CHECKS
|
||||||
|
if (!IsJumping && !_isJumpFalling && !isRegFalling && _moveInput.x != 0) {
|
||||||
|
if (!soundPlaying) {
|
||||||
|
// print("footsteps PLAY");
|
||||||
|
audioSource.Play();
|
||||||
|
soundPlaying = true;
|
||||||
|
}
|
||||||
|
} else if (soundPlaying && audioSource.clip.name == "footsteps") {
|
||||||
|
// print("footsteps stop");
|
||||||
|
audioSource.Stop();
|
||||||
|
soundPlaying = false;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region UPDATE UI
|
||||||
if (trumpet == 0) {
|
if (trumpet == 0) {
|
||||||
gameObject.transform.Find("Trumpet").GetComponent<AudioSource>().Play();
|
gameUI.ToggleTrumpet(false);
|
||||||
}
|
}
|
||||||
}
|
if (isDashing)
|
||||||
|
{
|
||||||
// stop sound if needed
|
gameUI.ToggleClarinet(false);
|
||||||
if (soundPlaying && (isRegFalling || IsJumping || _isJumpFalling)) {
|
|
||||||
print("footsteps stop");
|
|
||||||
audioSource.Stop();
|
|
||||||
soundPlaying = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
//WALL JUMP
|
|
||||||
// else if (CanWallJump() && LastPressedJumpTime > 0)
|
|
||||||
// {
|
|
||||||
// IsWallJumping = true;
|
|
||||||
// IsJumping = false;
|
|
||||||
// _isJumpCut = false;
|
|
||||||
// _isJumpFalling = false;
|
|
||||||
// _wallJumpStartTime = Time.time;
|
|
||||||
// _lastWallJumpDir = (LastOnWallRightTime > 0) ? -1 : 1;
|
|
||||||
//
|
|
||||||
// WallJump(_lastWallJumpDir);
|
|
||||||
// }
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region GRAPPLE CHECKS
|
|
||||||
// set wasGrappling to true if the player starts grappling
|
|
||||||
if (grapplingRope.isGrappling) {
|
|
||||||
wasGrappling = true;
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
|
|
||||||
#region SLIDE CHECKS
|
|
||||||
if (CanSlide() && ((LastOnWallLeftTime > 0 && _moveInput.x < 0) || (LastOnWallRightTime > 0 && _moveInput.x > 0)))
|
|
||||||
IsSliding = true;
|
|
||||||
else
|
|
||||||
IsSliding = false;
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region GRAVITY
|
|
||||||
//Higher gravity if we've released the jump input or are falling
|
|
||||||
if (IsSliding)
|
|
||||||
{
|
|
||||||
SetGravityScale(0);
|
|
||||||
}
|
|
||||||
else if (RB.velocity.y < 0 && _moveInput.y < 0)
|
|
||||||
{
|
|
||||||
//Much higher gravity if holding down
|
|
||||||
SetGravityScale(Data.gravityScale * Data.fastFallGravityMult);
|
|
||||||
//Caps maximum fall speed, so when falling over large distances we don't accelerate to insanely high speeds
|
|
||||||
RB.velocity = new Vector2(RB.velocity.x, Mathf.Max(RB.velocity.y, -Data.maxFastFallSpeed));
|
|
||||||
}
|
|
||||||
else if (_isJumpCut)
|
|
||||||
{
|
|
||||||
//Higher gravity if jump button released
|
|
||||||
SetGravityScale(Data.gravityScale * Data.jumpCutGravityMult);
|
|
||||||
RB.velocity = new Vector2(RB.velocity.x, Mathf.Max(RB.velocity.y, -Data.maxFallSpeed));
|
|
||||||
}
|
|
||||||
else if ((IsJumping || IsWallJumping || _isJumpFalling) && Mathf.Abs(RB.velocity.y) < Data.jumpHangTimeThreshold)
|
|
||||||
{
|
|
||||||
SetGravityScale(Data.gravityScale * Data.jumpHangGravityMult);
|
|
||||||
}
|
|
||||||
else if (RB.velocity.y < 0)
|
|
||||||
{
|
|
||||||
//Higher gravity if falling
|
|
||||||
SetGravityScale(Data.gravityScale * Data.fallGravityMult);
|
|
||||||
//Caps maximum fall speed, so when falling over large distances we don't accelerate to insanely high speeds
|
|
||||||
RB.velocity = new Vector2(RB.velocity.x, Mathf.Max(RB.velocity.y, -Data.maxFallSpeed));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//Default gravity if standing on a platform or moving upwards
|
|
||||||
SetGravityScale(Data.gravityScale);
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region SOUND CHECKS
|
|
||||||
if (!IsJumping && !_isJumpFalling && !isRegFalling && _moveInput.x != 0) {
|
|
||||||
if (!soundPlaying) {
|
|
||||||
// print("footsteps PLAY");
|
|
||||||
audioSource.Play();
|
|
||||||
soundPlaying = true;
|
|
||||||
}
|
}
|
||||||
} else if (soundPlaying && audioSource.clip.name == "footsteps") {
|
#endregion
|
||||||
// print("footsteps stop");
|
|
||||||
audioSource.Stop();
|
|
||||||
soundPlaying = false;
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region UPDATE UI
|
|
||||||
if (trumpet == 0) {
|
|
||||||
gameUI.ToggleTrumpet(false);
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -390,6 +394,7 @@ public class PlayerMovement : MonoBehaviour
|
|||||||
#region RUN METHODS
|
#region RUN METHODS
|
||||||
private void Run(float lerpAmount)
|
private void Run(float lerpAmount)
|
||||||
{
|
{
|
||||||
|
if(!isDashing){
|
||||||
//Calculate the direction we want to move in and our desired velocity
|
//Calculate the direction we want to move in and our desired velocity
|
||||||
float targetSpeed = _moveInput.x * Data.runMaxSpeed;
|
float targetSpeed = _moveInput.x * Data.runMaxSpeed;
|
||||||
//We can reduce are control using Lerp() this smooths changes to are direction and speed
|
//We can reduce are control using Lerp() this smooths changes to are direction and speed
|
||||||
@ -443,6 +448,7 @@ public class PlayerMovement : MonoBehaviour
|
|||||||
* RB.velocity = new Vector2(RB.velocity.x + (Time.fixedDeltaTime * speedDif * accelRate) / RB.mass, RB.velocity.y);
|
* RB.velocity = new Vector2(RB.velocity.x + (Time.fixedDeltaTime * speedDif * accelRate) / RB.mass, RB.velocity.y);
|
||||||
* Time.fixedDeltaTime is by default in Unity 0.02 seconds equal to 50 FixedUpdate() calls per second
|
* Time.fixedDeltaTime is by default in Unity 0.02 seconds equal to 50 FixedUpdate() calls per second
|
||||||
*/
|
*/
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Turn()
|
private void Turn()
|
||||||
@ -459,6 +465,7 @@ public class PlayerMovement : MonoBehaviour
|
|||||||
#region JUMP METHODS
|
#region JUMP METHODS
|
||||||
private void Jump()
|
private void Jump()
|
||||||
{
|
{
|
||||||
|
if(!isDashing){
|
||||||
//Ensures we can't call Jump multiple times from one press
|
//Ensures we can't call Jump multiple times from one press
|
||||||
LastPressedJumpTime = 0;
|
LastPressedJumpTime = 0;
|
||||||
LastOnGroundTime = 0;
|
LastOnGroundTime = 0;
|
||||||
@ -473,6 +480,7 @@ public class PlayerMovement : MonoBehaviour
|
|||||||
|
|
||||||
RB.AddForce(Vector2.up * force, ForceMode2D.Impulse);
|
RB.AddForce(Vector2.up * force, ForceMode2D.Impulse);
|
||||||
#endregion
|
#endregion
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void WallJump(int dir)
|
private void WallJump(int dir)
|
||||||
|
Loading…
Reference in New Issue
Block a user