private const int rumbleCount = 50; // Average the last X block positions to get the position of the rumble public void Update(float dt) { intervalTimer += dt; Entity targetEntity = this.Target.Value.Target; if (targetEntity != null && targetEntity.Active && this.Index < this.Coords.Length) { EffectBlockFactory factory = Factory.Get <EffectBlockFactory>(); Voxel m = targetEntity.Get <Voxel>(); float interval = 0.03f * this.IntervalMultiplier; while (intervalTimer > interval && this.Index < this.Coords.Length) { CoordinateEntry entry = this.Coords[this.Index]; Entity blockEntity = factory.CreateAndBind(main); EffectBlock effectBlock = blockEntity.Get <EffectBlock>(); entry.Coord.Data.ApplyToEffectBlock(blockEntity.Get <ModelInstance>()); effectBlock.CheckAdjacent = false; effectBlock.Offset.Value = m.GetRelativePosition(entry.Coord); effectBlock.DoScale = true; effectBlock.StartPosition = entry.Position + new Vector3(8.0f, 20.0f, 8.0f) * this.BlockLifetime.Value; effectBlock.StartOrientation = Quaternion.CreateFromYawPitchRoll(0.15f * this.Index, 0.15f * this.Index, 0); effectBlock.TotalLifetime = this.BlockLifetime; effectBlock.Setup(targetEntity, entry.Coord, entry.Coord.Data.ID); main.Add(blockEntity); this.rumbleSum += entry.Position; int lastIndex = this.Index - rumbleCount; if (lastIndex >= 0) { this.rumbleSum -= this.Coords[lastIndex].Position; } this.Index.Value++; intervalTimer -= interval; } if (this.Coords.Count > 200) { this.RumblePosition.Value = this.rumbleSum / Math.Min(this.Index + 1, rumbleCount); if (!this.rumbling) { AkSoundEngine.PostEvent(AK.EVENTS.PLAY_BLOCK_RUMBLE, this.Entity); this.rumbling = true; } } } else { this.Delete.Execute(); } }
public void Update(float dt) { intervalTimer += dt; Entity targetEntity = this.Target.Value.Target; if (targetEntity != null && targetEntity.Active && this.Index < this.Coords.Length) { float interval = 0.03f * this.IntervalMultiplier; while (intervalTimer > interval && this.Index < this.Coords.Length) { EffectBlockFactory factory = Factory.Get <EffectBlockFactory>(); Voxel m = targetEntity.Get <Voxel>(); CoordinateEntry entry = this.Coords[this.Index]; Entity blockEntity = factory.CreateAndBind(main); EffectBlock effectBlock = blockEntity.Get <EffectBlock>(); entry.Coord.Data.ApplyToEffectBlock(blockEntity.Get <ModelInstance>()); effectBlock.CheckAdjacent = false; effectBlock.Offset.Value = m.GetRelativePosition(entry.Coord); effectBlock.DoScale = true; effectBlock.StartPosition = entry.Position + new Vector3(8.0f, 20.0f, 8.0f) * this.BlockLifetime.Value; effectBlock.StartOrientation = Quaternion.CreateFromYawPitchRoll(0.15f * this.Index, 0.15f * this.Index, 0); effectBlock.TotalLifetime = this.BlockLifetime; effectBlock.Setup(targetEntity, entry.Coord, entry.Coord.Data.ID); main.Add(blockEntity); this.Index.Value++; intervalTimer -= interval; } } else { this.Delete.Execute(); } }