public RaycastHit2D isGrounded() { float dist = (walkCollider.bounds.extents.x * 2f) - .15f; return(PhysicsHelper2D.visibleRaycast((Vector2)transform.position + new Vector2(-walkCollider.bounds.extents.x + .075f, -walkCollider.edgeRadius - .025f), Vector2.right, dist, walkMask)); }
RaycastHit2D wallContact(bool right) { float xOffset = (walkCollider.bounds.extents.x + walkCollider.edgeRadius) + .1f; return(PhysicsHelper2D.visibleRaycast((Vector2)transform.position + new Vector2((right ? xOffset : -xOffset), .1f), Vector2.up, (walkCollider.bounds.extents.y + walkCollider.edgeRadius) * 1.8f, walkMask)); }
bool isColliderUnderUmbrella(BoxCollider2D collider) { float colliderHalfWidth = collider.bounds.extents.x; float yOffset = 3.75f; var hit = PhysicsHelper2D.visibleRaycast((Vector2)(new Vector3(collider.transform.position.x - colliderHalfWidth, yOffset, 0f)), Vector2.right, colliderHalfWidth * 2f); return(hit && hit.collider.name.Equals("UmbrellaShadow")); }
void updatePlatforming() { int direction = 0; if (hasControl) { if (Input.GetKey(KeyCode.LeftArrow) && !wallContact(false)) { direction -= 1; } if (Input.GetKey(KeyCode.RightArrow) && !wallContact(true)) { direction += 1; } } else //if ((forceDirection == 1 && !wallContact(true)) || (forceDirection == -1 && !wallContact(false))) { direction = forceDirection; } RaycastHit2D groundHit = isGrounded(); bool grounded = groundHit; // && _rigidBody2D.velocity.y <= 0f; if (grounded) { //Snap to ground y when landing if (_rigidBody2D.velocity.y < 0f && transform.position.y < groundHit.transform.position.y && transform.position.y >= groundHit.transform.position.y - maxLandSnapHeight) { //float snapY = groundHit.transform.position.y + (groundHit.collider.bounds.extents.y); transform.position = new Vector3(transform.position.x, groundHit.transform.position.y, transform.position.z); _rigidBody2D.velocity = new Vector2(_rigidBody2D.velocity.x, 0f); } //Attach to moving objects if (groundHit.transform.name.Contains("Moving")) { transform.parent = groundHit.transform; } else { transform.parent = startParent; } //Jump if (hasControl && Input.GetKeyDown(KeyCode.Space)) { _rigidBody2D.velocity = new Vector2(_rigidBody2D.velocity.x, jumpSpeed); grounded = false; transform.parent = startParent; } } else { transform.parent = startParent; } int actualDirection = _rigidBody2D.velocity.x == 0 ? 0 : (int)Mathf.Sign(_rigidBody2D.velocity.x); if (actualDirection == 0 && direction != 0) { actualDirection = direction; } updateSpinner((direction == 0 || (direction != 0 && actualDirection != direction)) ? 0 : actualDirection); updateWalkSpeed(direction, grounded); updateAnimatorValues(direction, grounded); //Bounds stuff if (direction == 0) { RaycastHit2D leftWallHit = wallContact(false); if (leftWallHit && leftWallHit.collider.transform.parent == boundsParent) { if (leftWallHit && wallContact(true)) { float dist = (walkCollider.bounds.extents.x * 2f) - .15f; if (PhysicsHelper2D.visibleRaycast((Vector2)transform.position + new Vector2(-walkCollider.bounds.extents.x + .075f, walkCollider.bounds.extents.y), Vector2.right, dist, walkMask)) { kill(true); } } else if (grounded && PaperThiefCamera.instance.getCurrentShiftSpeed() > 1f) { actualDirection = direction = 1; updateSpinner(1); rigAnimator.SetBool("Walking", true); rigAnimator.SetFloat("WalkSpeed", 1f); } } } if (hasControl && transform.position.x >= cucumberTransform.position.x - 1f) { PaperThiefController.instance.startScene(PaperThiefController.Scene.CucumberSteal); if (_rigidBody2D.velocity.y > 0f) { _rigidBody2D.velocity = new Vector2(_rigidBody2D.velocity.x, 0f); } } else if (PaperThiefMarisa.defeated && transform.position.x >= victoryTransform.position.x - .5f) { forceDirection = 0; PaperThiefController.instance.startScene(PaperThiefController.Scene.Victory); MicrogameController.instance.setVictory(true, true); } }