diff --git a/MrBigsock/Assets/Code/Character.cs b/MrBigsock/Assets/Code/Character.cs index 5e5f6cde48ae60121bbe050472844cd9c1b6a1d4..3a04ccfd00919e28e66af357d3fb610280ac3888 100644 --- a/MrBigsock/Assets/Code/Character.cs +++ b/MrBigsock/Assets/Code/Character.cs @@ -98,6 +98,17 @@ namespace BigSock { } + /* + Try to move in a given direction. + */ + protected virtual bool TryMove(Vector2 direction) { + if(direction != Vector2.zero) { + rb.AddForce(direction * (float) MovementSpeed * Time.fixedDeltaTime, ForceMode2D.Impulse); + return true; + } + return false; + } + /* Adds damage to the player if they don't have IFrames. */ diff --git a/MrBigsock/Assets/Code/PlayerController.cs b/MrBigsock/Assets/Code/PlayerController.cs index ded60e8fd892620751caba3bed7d107cd9437678..0711143f7fb5eb7509ca9b5ae0815edff431225b 100644 --- a/MrBigsock/Assets/Code/PlayerController.cs +++ b/MrBigsock/Assets/Code/PlayerController.cs @@ -104,15 +104,8 @@ namespace BigSock { } } - - private bool TryMove(Vector2 direction) { - if(direction != Vector2.zero) { - rb.AddForce(direction * (float) MovementSpeed * Time.fixedDeltaTime, ForceMode2D.Impulse); - return true; - } - return false; - } + private bool TryMove_OLD(Vector2 direction) { if(direction != Vector2.zero) { diff --git a/MrBigsock/Assets/Code/Slime/SlimeController.cs b/MrBigsock/Assets/Code/Slime/SlimeController.cs index a7d612764b42147510de8700dc9ccd8b0895a0af..f8b89ba4552430b3ecc6f0f16489c05efa57c4e4 100644 --- a/MrBigsock/Assets/Code/Slime/SlimeController.cs +++ b/MrBigsock/Assets/Code/Slime/SlimeController.cs @@ -118,7 +118,8 @@ namespace BigSock { var temp = (pos - rb.transform.position); temp.z = 0; var direction = temp.normalized; - rb.AddForce((float) LeapForce * direction, ForceMode2D.Impulse); + //rb.AddForce((float) LeapForce * direction, ForceMode2D.Impulse); + TryMove(direction); // Update the state. State = SlimeState.Leaping; @@ -139,36 +140,18 @@ namespace BigSock { } - private bool TryMove(Vector2 direction) { - + + /* + Try to move in a given direction. + */ + protected override bool TryMove(Vector2 direction) { if(direction != Vector2.zero) { - - // Check for potential collisions - int count = rb.Cast( - direction, // X and Y values between -1 and 1 that represent the direction from the body to look for collisions - movementFilter, // The settings that determine where a collision can occur on such as layers to collide with - castCollisions, // List of collisions to store the found collisions into after the Cast is finished - (float) MovementSpeed * Time.fixedDeltaTime + collisionOffset); // The amount to cast equal to the movement plus an offset - //Debug.Log($"cast {string.Join(", ", castCollisions.Select(x => $"{x.collider.isTrigger}"))}"); - //Debug.Log($"rb.position : {rb.position}"); - //Debug.Log($"target.position : {target.position}"); - //Debug.Log($"direction : {direction}"); - if(count == 0){ - rb.MovePosition(rb.position + direction * (float) MovementSpeed * Time.fixedDeltaTime); - //print($"rb.position {rb.position}"); - //print($"direction {direction}"); - RotateAnimation(direction); - - return true; - } else { - return false; - } - } else { - // Can't move if there's no direction to move in - return false; + rb.AddForce((float) LeapForce * direction, ForceMode2D.Impulse); + return true; } - + return false; } + } diff --git a/MrBigsock/Assets/Code/orc/EnemyController.cs b/MrBigsock/Assets/Code/orc/EnemyController.cs index 02dbc762456227f5c5d611e608ae3ebc39ed41eb..fb98ebe58dffa93a1d9e4ca4322caf8c6c82af23 100644 --- a/MrBigsock/Assets/Code/orc/EnemyController.cs +++ b/MrBigsock/Assets/Code/orc/EnemyController.cs @@ -78,13 +78,7 @@ namespace BigSock { } } - private bool TryMove(Vector2 direction) { - if(direction != Vector2.zero) { - rb.AddForce(direction * (float) MovementSpeed * Time.fixedDeltaTime, ForceMode2D.Impulse); - return true; - } - return false; - } + private bool TryMove_OLD(Vector2 direction) {