public void Tick() { foreach (var entity in PhysicsEntities.ToArray()) { if (entity is Entity e) { if (e.NoAi) { continue; } var blockcoords = e.KnownPosition.GetCoordinates3D(); //.BlockDown(); if (Math.Round(e.KnownPosition.Y, 2) % 1 == 0) { blockcoords = blockcoords.BlockDown(); //offset = 1f; } var block = World.GetBlock(blockcoords.X, blockcoords.Y, blockcoords.Z); float drag = (float)(1f - e.Drag); if (e.KnownPosition.OnGround) { var slipperiness = (float)block.BlockMaterial.Slipperiness; slipperiness *= 0.91f; var multiplier = (float)(0.1 * (0.1627714 / (slipperiness * slipperiness * slipperiness))); entity.Velocity *= new Vector3(slipperiness, 1f, slipperiness); } else if (!e.IsFlying && !e.KnownPosition.OnGround && e.IsAffectedByGravity) { drag = 0.91f; entity.Velocity -= new Vector3(0f, (float)(e.Gravity), 0f); //var modifier = new Vector3(1f, (float) (1f - (e.Gravity * dt)), 1f); //velocity *= modifier; } entity.Velocity *= new Vector3(drag, 0.98f, drag); UpdateOnGround(e); //TruncateVelocity(e, 0f); //CheckCollision(e); } } _timeSinceTick.Restart(); }
public bool Remove(IPhysicsEntity entity) { return(PhysicsEntities.Remove(entity)); }
public bool AddTickable(IPhysicsEntity entity) { return(PhysicsEntities.TryAdd(entity)); }