void limitVelocity(Entity e) { VelocityLimitComponent velocityLimit = e.velocityLimit; VelocityComponent velocity = e.velocity; if (velocity.vel.magnitude > velocityLimit.maxVelocity) { velocity.vel.Normalize(); velocity.vel *= velocityLimit.maxVelocity; } }
public void Execute() // todo: can cause speed bugs { float deltaTime = _time.GetSingleEntity().time.deltaTime; Entity player = _player.GetSingleEntity(); VelocityLimitComponent limit = player.velocityLimit; foreach (Entity e in _group.GetEntities()) { SpeedBonusComponent component = e.speedBonus; component.time -= deltaTime; if (component.time < 0.0f) { limit.maxVelocity = component.savedVelocity; e.isDestroyEntity = true; } else { component.savedVelocity = limit.maxVelocity; limit.maxVelocity = component.velocity; } } }