private void DetermineAffectingField() { if (!fields.Any()) { affectingField = null; return; } foreach (var field in fields) { int index = GetFieldIndex(field.FieldType); if (index == -1) { continue; } if (affectingField == null) { affectingField = field; timeSwitched = Time.time; originalVelocity = body.velocity; } else if (index <= GetFieldIndex(affectingField.FieldType)) { affectingField = field; timeSwitched = Time.time; originalVelocity = body.velocity; } } }
public void SetTargetPlanet(GravField gravField) { //Sets the target planet for collison detection and movement if (gravField != null) { TargetPlanet = gravField.transform.parent; this.gravity = gravField.gravity; this.planetFriction = gravField.planetFriction; this.atmosphereFriction = gravField.atmosphereFriction; planetRadius = TargetPlanet.transform.localScale.x * TargetPlanet.GetComponent <CircleCollider2D>().radius; } }
private void Update() { if (affectingField == null) { return; } if (!affectingField.IsActive) { affectingField = null; return; } float ratio = (Time.time - timeSwitched) / lerpTime; body.velocity = Vector2.Lerp(originalVelocity, affectingField.GetFieldVelocity(), ratio); }