/// <summary> /// Predicts to see if the new location is valid for collision by scanning one directions through raycast. /// </summary> private bool _IsNewLocationValid(InputManager.DIRECTION direction) { RaycastHit2D hit = RaycastAtDirection(direction); if (hit != null && hit.collider != null) { if (hit.collider.tag == "Stage") { if (direction == InputManager.DIRECTION.LEFT || direction == InputManager.DIRECTION.RIGHT) { m_thisTransform.position = new Vector2(m_thisTransform.position.x, hit.collider.gameObject.transform.position.y + m_horiRaycastDist + hit.collider.bounds.extents.y + hit.collider.offset.x); } else // DIRECTION.UP AND DOWN { float colliderYRadius = hit.collider.bounds.extents.y; float colliderCenter = hit.collider.gameObject.transform.position.y + (hit.collider.offset.y * hit.transform.localScale.y); float yPos = colliderCenter + colliderYRadius + m_vertRaycastDist; // + m_thisTransform.position = new Vector2(m_thisTransform.position.x, yPos); } return(false); } } return(true); }
/// <summary> /// Predicts to see if the new location is valid for collision by scanning all directions through raycast. /// </summary> private bool _IsNewLocationValid(InputManager.DIRECTION direction, params InputManager.DIRECTION[] directionValues) //(InputManager.DIRECTION direction, params InputManager.DIRECTION[] directionValues) { /* * for (int i = -1; i < directionValues; i++) * { * if (i == -1) * { * if (_IsNewLocationValid(direction); * } * else * { * * } * } * return true; */ return(true); }
private RaycastHit2D RaycastAtDirection(InputManager.DIRECTION direction) { Vector2 rectSize = Vector2.zero; Vector2 castDirection = Vector2.zero; float castDistance = 0.0f; switch (direction) { case InputManager.DIRECTION.DOWN: castDirection = Vector2.down; rectSize.x = m_playerCollider.bounds.size.x; castDistance = m_vertRaycastDist; break; case InputManager.DIRECTION.LEFT: castDirection = Vector2.left; rectSize.y = m_playerCollider.bounds.size.y; castDistance = m_horiRaycastDist; break; case InputManager.DIRECTION.UP: castDirection = Vector2.up; rectSize.x = m_playerCollider.bounds.size.x; castDistance = m_vertRaycastDist; break; case InputManager.DIRECTION.RIGHT: castDirection = Vector2.right; rectSize.y = m_playerCollider.bounds.size.y; castDistance = m_horiRaycastDist; break; default: break; } RaycastHit2D hit = Physics2D.Raycast(m_newPosition, castDirection, castDistance, m_layerMask); return(hit); }
private void _CalculateY(InputManager.DIRECTION input) { // Receive input and jump if (input == InputManager.DIRECTION.JUMP) { m_moveY = JUMP_STRENGTH; m_bIsJumping = true; if (m_currOrient == InputManager.DIRECTION.LEFT) { m_bIsJumpingRight = false; } else if (m_currOrient == InputManager.DIRECTION.RIGHT) { m_bIsJumpingRight = true; } if (m_bIsJumpingRight) { m_playerAnim.SetInteger("Direction", 23); } else { m_playerAnim.SetInteger("Direction", 21); } } // if Midair if (m_bIsJumping) { m_moveY -= GRAV_STRENGTH * Time.deltaTime; } m_moveY = Mathf.Clamp(m_moveY, -FALL_LIMIT, FALL_LIMIT); }
//private InputManager.DIRECTION private void _ManageAnimation() { if (m_playerAnim == null) { return; } InputManager.DIRECTION charDirection = InputManager.Instance.GetInputAlways(m_playerID); // If a button is being pressed if (charDirection != InputManager.DIRECTION.NEUTRAL) { switch (charDirection) { case InputManager.DIRECTION.DOWN: m_playerAnim.SetInteger("Direction", 0); break; case InputManager.DIRECTION.LEFT: m_playerAnim.SetInteger("Direction", 1); break; case InputManager.DIRECTION.UP: m_playerAnim.SetInteger("Direction", 2); break; case InputManager.DIRECTION.RIGHT: m_playerAnim.SetInteger("Direction", 3); break; default: break; } m_prevOrient = charDirection; } switch (InputManager.Instance.GetInputUp(m_playerID)) { case InputManager.DIRECTION.DOWN: m_playerAnim.SetInteger("Direction", 10); break; case InputManager.DIRECTION.LEFT: m_playerAnim.SetInteger("Direction", 11); break; case InputManager.DIRECTION.RIGHT: m_playerAnim.SetInteger("Direction", 13); break; case InputManager.DIRECTION.UP: m_playerAnim.SetInteger("Direction", 12); break; } /* * else * if (charDirection == InputManager.DIRECTION.NEUTRAL && m_prevOrient != charDirection) * { * switch (m_currOrient) * { * case InputManager.DIRECTION.DOWN: * m_playerAnim.SetInteger("Direction", 10); * break; * case InputManager.DIRECTION.LEFT: * m_playerAnim.SetInteger("Direction", 11); * break; * case InputManager.DIRECTION.RIGHT: * m_playerAnim.SetInteger("Direction", 12); * break; * case InputManager.DIRECTION.UP: * m_playerAnim.SetInteger("Direction", 13); * break; * } * m_prevOrient = charDirection; * } */ //Debug.Log(m_prevOrient); }
private InputManager.DIRECTION _GetInputDown() { m_currOrient = InputManager.Instance.GetInputDown(m_playerID); return(m_currOrient); }
private void _CalculateX(InputManager.DIRECTION input) { float currFrame_moveX = ACCEL_X * Time.fixedDeltaTime; float currFrame_decelX = DECEL_X * Time.fixedDeltaTime; // Inline Input if (_GetInputAlways() != InputManager.DIRECTION.NEUTRAL) { // check to see if you walked off a cliff if (_IsNewLocationValid(InputManager.DIRECTION.DOWN)) { m_bIsJumping = true; m_bIsFalling = true; } } switch (input) { case InputManager.DIRECTION.LEFT: if (m_moveX > 0f) { m_moveX -= currFrame_decelX; } else { m_moveX -= currFrame_moveX; } break; case InputManager.DIRECTION.RIGHT: if (m_moveX < 0f) { m_moveX += currFrame_decelX; } else { m_moveX += currFrame_moveX; } break; default: if (m_moveX > 0f) { if (m_moveX - currFrame_decelX > 0f) { m_moveX -= currFrame_decelX; } else { m_moveX = 0f; } } else if (m_moveX < 0f) { if (m_moveX < 0f) { if (m_moveX + currFrame_decelX < 0f) { m_moveX += currFrame_decelX; } else { m_moveX = 0f; } } } break; } // speed limit m_moveX = Mathf.Clamp(m_moveX, -LIMIT_X, LIMIT_X); }