private bool CheckIfGrounded() { ColliderLimits _colliderLimits = GetColliderLimits(); Vec2 bottomLeft = World.WorldToTileCoords(_colliderLimits.xMin + 0.03f, _colliderLimits.yMin - 0.03f); // Necessary the way this works Vec2 bottomRight = World.WorldToTileCoords(_colliderLimits.xMax - 0.03f, _colliderLimits.yMin - 0.03f); if (MapData.mapArray[bottomLeft.x, bottomLeft.y].IsSolid() || MapData.mapArray[bottomRight.x, bottomRight.y].IsSolid()) { return(true); } return(false); }
public Vector2 MoveCharacter(int h_Axis, float speed) { isGrounded = CheckIfGrounded(); cLimits = GetColliderLimits(); // h is 1, 0, or -1. if it's 0, speed will be 0, otherwise it'll be speed in case of 1, -speed in case of -1; maxSpeed = speed * h_Axis; // calculate tile grip // // account for friction and grip ModifyCurrentSpeed(); movement.x = (currentSpeed / 10) * Time.deltaTime + forceVector.x * Time.deltaTime; forceVector.x -= 10f * Time.deltaTime; if (forceVector.x < 0) { forceVector.x = 0; } movement.y = (gravityForce * Time.deltaTime + forceVector.y * Time.deltaTime); // + jumpForce * Time.deltaTime forceVector.y += gravityForce / 30; if (forceVector.y < 0) { forceVector.y = 0; } if (movement.x > 0) { CheckRightCollisions(); } if (movement.x < 0) { CheckLeftCollisions(); } if (movement.y <= 0) { CheckDownCollision(); } if (movement.y > 0) { CheckUpCollision(); } if (Debugging.debuggingMovement) { Debugging.xMovement = movement.x; } finalMovement.x = transform.position.x + movement.x; finalMovement.y = transform.position.y + movement.y; transform.position = finalMovement; return(movement); // // movement.y = (gravityForce * Time.deltaTime) + jumpForce * Time.deltaTime; //* downwardsAcceleration * }