public C_PendulumController(C_PlayerController player, GrapplingHookController hook) { Hook = hook; Pivots = hook.Pivots; Pendulum = hook.Body; Player = player; Radius = 20; AnchorObject = player; PendulumObject = hook; Anchor = Player.body; }
public void Switch() { Pivots.RemoveAt(0); List <Pivot> nList = new List <Pivot> (); while (Pivots.Count > 0) { Pivot temp = Pivots [Pivots.Count - 1]; nList.Add(temp); Pivots.Remove(temp); } Pivot pivot = new Pivot(Hook.Body.position); nList.Insert(0, pivot); Pivots = nList; AnchorObject = Hook; PendulumObject = Player; Pendulum = Player.body; Anchor = Hook.Body; Vector2 secondaryAnchor; if (Pivots.Count > 1) { secondaryAnchor = Pivots [1].Position; } else { secondaryAnchor = Pendulum.position; } RaycastHit2D empty = new RaycastHit2D(); RaycastHit2D result; while ((result = GetHits(pivot.Position, secondaryAnchor, empty)) != empty) { Vector2 directionVec = (secondaryAnchor - new Vector2(result.collider.bounds.center.x, result.collider.bounds.center.y)); directionVec.Normalize(); pivot.Position = pivot.Position + (0.2f * directionVec); while (result.collider.bounds.Contains(pivot.Position)) { pivot.Position += 0.2f * directionVec; } } Radius = (pivot.Position - Pendulum.position).magnitude; }