void Start() { heroAnimator = GetComponentInChildren <Animator>(); heroRenderer = GetComponentInChildren <SpriteRenderer>(); heroPhysics = GetComponent <HeroPhysics>(); defaultColor = heroRenderer.color; gravity *= -1; jumps = maxJumps; invincibleTimer = timeInvincible; source = Camera.main.GetComponent <AudioSource>(); }
void CalculatePassengerMovement(float rotation) { HashSet <Transform> movedPassengers = new HashSet <Transform> (); passengerMovement = new List <PassengerMovement> (); Collider2D[] colliders = Physics2D.OverlapCircleAll(collider2d.bounds.center, collider2d.radius + RaycastController.skinWidth); foreach (var hit in colliders) { HeroPhysics heroPhysics = hit.GetComponent <HeroPhysics>(); if (heroPhysics == null) { continue; } bool above = hit.transform.position.y > transform.position.y; if (!above) { continue; } if (!movedPassengers.Contains(hit.transform)) { movedPassengers.Add(hit.transform); float angle = Vector2.Angle(Vector2.right, transform.position - hit.transform.position); float originX = collider2d.radius * Mathf.Cos(Mathf.Deg2Rad * angle); float originY = collider2d.radius * Mathf.Sin(Mathf.Deg2Rad * angle); float targetX = collider2d.radius * Mathf.Cos(Mathf.Deg2Rad * (angle + rotation)); float targetY = collider2d.radius * Mathf.Sin(Mathf.Deg2Rad * (angle + rotation)); float deltaX = originX - targetX; float deltaY = originY - targetY; passengerMovement.Add(new PassengerMovement(hit.transform, new Vector3(deltaX, deltaY), true)); } } }