Updated PlayerController.cs
This commit is contained in:
@@ -7,21 +7,35 @@ namespace Player
|
||||
{
|
||||
public class PlayerController : MonoBehaviour, IMovement, Input.PlayerInput.IPlayerControlActions
|
||||
{
|
||||
private const float DefaultJumpForce = 1200.0f;
|
||||
private const float DefaultMass = 80.0f;
|
||||
private const float DefaultSpeed = 500.0f;
|
||||
private const float GravityScale = 3.0f;
|
||||
|
||||
private Input.PlayerInput _controls;
|
||||
private Rigidbody2D _playerRigidbody2D;
|
||||
private SpriteRenderer _playerSpriteRenderer;
|
||||
private CollisionChecker _playerGroundTrigger;
|
||||
|
||||
private bool _moveKeyPressed;
|
||||
private bool _jumpKeyPressed;
|
||||
|
||||
private bool _canJump = true;
|
||||
private bool _isOnAir;
|
||||
|
||||
private float _xAxisValue;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
this._playerRigidbody2D = GameObject.Find("Player").GetComponent<Rigidbody2D>();
|
||||
this._playerRigidbody2D = gameObject.GetComponent<Rigidbody2D>();
|
||||
this._playerGroundTrigger = GameObject.Find("PlayerGroundTrigger").GetComponent<CollisionChecker>();
|
||||
this._playerSpriteRenderer = gameObject.GetComponent<SpriteRenderer>();
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
this._playerRigidbody2D.gravityScale = GravityScale;
|
||||
this._playerRigidbody2D.mass = DefaultMass;
|
||||
BaseSpeed = DefaultSpeed;
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
@@ -47,22 +61,22 @@ namespace Player
|
||||
else
|
||||
_playerRigidbody2D.velocity = new Vector2(0.0f, _playerRigidbody2D.velocity.y);
|
||||
|
||||
if (_jumpKeyPressed)
|
||||
if (_jumpKeyPressed && _playerGroundTrigger.IsCollided)
|
||||
Jump();
|
||||
}
|
||||
|
||||
// PAUSE METHODS
|
||||
|
||||
public bool IsPaused { get; }
|
||||
public bool IsPaused { get; private set; }
|
||||
|
||||
public void Pause()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
IsPaused = true;
|
||||
}
|
||||
|
||||
public void Resume()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
IsPaused = false;
|
||||
}
|
||||
|
||||
// MOVE METHODS
|
||||
@@ -87,7 +101,8 @@ namespace Player
|
||||
|
||||
private void Jump()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
_playerRigidbody2D.velocity = new Vector2(_playerRigidbody2D.velocity.x, 0);
|
||||
_playerRigidbody2D.AddForce(Vector2.up.normalized * DefaultJumpForce, ForceMode2D.Impulse);
|
||||
}
|
||||
|
||||
private void Climb()
|
||||
@@ -117,7 +132,6 @@ namespace Player
|
||||
{
|
||||
case true:
|
||||
_jumpKeyPressed = false;
|
||||
_canJump = true;
|
||||
break;
|
||||
case false:
|
||||
_jumpKeyPressed = true;
|
||||
|
Reference in New Issue
Block a user