private float GetAngleFromSurfaceDirection(surfaceDirection direction) { float angle = 0; switch (direction) { case surfaceDirection.up: angle = 90; break; case surfaceDirection.down: angle = 270; break; case surfaceDirection.right: angle = 0; break; case surfaceDirection.left: angle = 180; break; } return(angle); }
private IEnumerator JumpShot(Vector2 jumpShotDirection) { jumpShotCooldownRemaining = jumpShotCooldown; isJumping = true; onSurface = false; jumpCollisionDelay = 0.2f; while (!isTouchingWall) { Propel(jumpShotDirection * jumpSpeed, true, true); if (Physics2D.OverlapCircle(transform.position, jumpShotDamageRange, LayerMask.GetMask("Player"))) { Vector2 playerDirection = GameData.playerMovement.transform.position - transform.position; playerDirection.Normalize(); GameData.playerManager.TakeDamage(jumpShotDamage, playerDirection * jumpShotKnockbackForce, jumpShotStunTime); } yield return(new WaitForFixedUpdate()); } isJumping = false; onSurface = true; Propel(Vector2.zero, true, true); Vector2 vectorSurfaceDirection = (Vector2)transform.position - collisionPoint; currentSurfaceDirection = GetDirectionFromVector(vectorSurfaceDirection); spriteTransform.rotation = Quaternion.Euler(0.0f, 0.0f, GetAngleFromSurfaceDirection(currentSurfaceDirection) - 90); }
void Start() { HandlerStart(); jumpShotCooldownRemaining = 0; onSurface = true; isTouchingWall = false; currentSurfaceDirection = startSurfaceDirection; }
private surfaceDirection GetDirectionFromVector(Vector2 direction) { float minCollisionAngleDifference = 360; int i = 0; surfaceDirection lastSurfaceDirection = surfaceDirection.none; while (i < 4 && minCollisionAngleDifference >= 45) { Vector2 originDirection = Vector2.zero; switch (i) { case 0: originDirection = Vector2.up; lastSurfaceDirection = surfaceDirection.up; break; case 1: originDirection = Vector2.down; lastSurfaceDirection = surfaceDirection.down; break; case 2: originDirection = Vector2.right; lastSurfaceDirection = surfaceDirection.right; break; case 3: originDirection = Vector2.left; lastSurfaceDirection = surfaceDirection.left; break; } float collisionAngle = Vector2.Angle(originDirection, direction); if (minCollisionAngleDifference > collisionAngle) { minCollisionAngleDifference = collisionAngle; } i++; } return(lastSurfaceDirection); }