/// <inheritdoc/> protected override void Update(Time time) { if (!(this.Owner is PlatformCharacter)) { return; } //Calculate from Speed later? double yTolerance = 10.0; double xTolerance = 10.0; PlatformCharacter pc = this.Owner as PlatformCharacter; if (_triesToJump) { //Brains are walking against a wall: if (Math.Abs(pc.Velocity.X) < 5) { //If position hasn't changed since last jump, change direction. if ((pc.Position - lastJumpingPosition).Magnitude < 1) { pc.Stop(); this.Speed *= -1; } else { pc.Jump(JumpSpeed); lastJumpingPosition = pc.Position; //Brains don't change direction in mid-air while jumping: if (!_fallsOffPlatforms) { _fallsOffPlatforms = true; Timer.SingleShot(0.5, delegate { _fallsOffPlatforms = false; }); } } } } //Changes direction if it's about to fall off a platform: if (!_fallsOffPlatforms && pc.IsAboutToFall() && Math.Abs(pc.Velocity.Y) < yTolerance) { pc.Stop(); if (_triesToJump && Math.Abs(pc.Velocity.X) < xTolerance) { this.Speed *= -1; } } if (!_triesToJump && Math.Abs(pc.Velocity.X) < xTolerance) { this.Speed *= -1; } pc.Walk(this.Speed); base.Update(time); }