private void Update() { if (decision == 0) { var chance = waitChance + boostChance + turboChance; var next = random.Next(chance); if (next < waitChance) { decision = 1; } else if (next < boostChance) { decision = 2; } else { decision = 3; } } switch (decision) { case 2 when ship.CanBoost(): case 3 when ship.CanTurbo(): OnDirectionChanged?.Invoke(direction); break; default: OnDirectionChanged?.Invoke(0); break; } }
protected override void Awake() { base.Awake(); inputAction = new ShipInputAction(); inputAction.ShipControls.ChangeLane.performed += ctx => { if (ctx.control.device is Touchscreen) { var controlParent = ctx.control.parent; var x = (controlParent as TouchControl)?.position.x; if (x?.ReadValue() > Screen.width / 2f) { OnDirectionChanged?.Invoke(1); } else { OnDirectionChanged?.Invoke(-1); } } else { OnDirectionChanged?.Invoke(Math.Sign(ctx.ReadValue <float>())); } }; inputAction.ShipControls.ChangeLane.canceled += ctx => { OnDirectionChanged?.Invoke(0); }; }
private void UpdateDirection(double azimuthRadians) { lock (this) { var sectorCount = 6; var sectorSize = (2 * Math.PI) / sectorCount; var sector = Math.Ceiling((azimuthRadians + Math.PI) / sectorSize); var heading = (sectorSize * sector) - Math.PI; //if (heading.Equals(_lastHeading)) // return; _recentHeadings.Enqueue(heading); var averageHeading = _recentHeadings.Average(); //if (heading % averageHeading > 2) // return; _lastHeading = heading; OnDirectionChanged?.Invoke(new DirectionChangedEventArgs(azimuthRadians, averageHeading)); } }
public void ChangeDirection(JumpDirection jumpDirection) { OnDirectionChanged?.Invoke(jumpDirection); }
public void SetDirection(Direction newDirection) { MoveDirection = newDirection; OnDirectionChanged?.Invoke(); }