public override void UpdateAfterSimulation() { base.UpdateAfterSimulation(); // DA: Consider using havok fields (buoyancy demo) for gravity of planets. Vector3 gravity = MyGravityProviderSystem.CalculateGravityInPointForGrid(PositionComp.GetPosition()); Physics.AddForce(Engine.Physics.MyPhysicsForceType.APPLY_WORLD_FORCE, Physics.Mass * gravity, Physics.CenterOfMassWorld, null); }
private bool IsNearPlanet() { if (ControlledEntity == null) { return(false); } return(!Vector3.IsZero(MyGravityProviderSystem.CalculateGravityInPointForGrid(ControlledEntity.PositionComp.GetPosition()))); }
private void CutTree(int itemInstanceId, Vector3D hitWorldPosition, Vector3 hitNormal, float forceMultiplier = 1.0f) { HkStaticCompoundShape shape = (HkStaticCompoundShape)Physics.RigidBody.GetShape(); int physicsInstanceId; if (m_localIdToPhysicsShapeInstanceId.TryGetValue(itemInstanceId, out physicsInstanceId)) { //Remove static tree MyEnvironmentItemData itemData = m_itemsData[itemInstanceId]; RemoveItem(itemInstanceId, physicsInstanceId, sync: true); //Create fractured tree MyDefinitionId id = new MyDefinitionId(Definition.ItemDefinitionType, itemData.SubtypeId); var itemDefinition = MyDefinitionManager.Static.GetEnvironmentItemDefinition(id); if (MyModels.GetModelOnlyData(itemDefinition.Model).HavokBreakableShapes != null) { CreateBreakableShape(itemDefinition, ref itemData, ref hitWorldPosition, hitNormal, forceMultiplier); } else { // This is for SE when you hit a tree, it will create a floating object with the same model. In case it affects ME, it may be changed. Contact DusanA for it. Debug.Assert(MyPerGameSettings.Game == GameEnum.SE_GAME); MyPhysicalInventoryItem Item = new MyPhysicalInventoryItem() { Amount = 1, Content = new MyObjectBuilder_TreeObject() { SubtypeName = itemData.SubtypeId.ToString() } }; Vector3D pos = itemData.Transform.Position; Vector3D gravity = -MyGravityProviderSystem.CalculateGravityInPointForGrid(pos); gravity.Normalize(); MyFloatingObjects.Spawn(Item, pos + gravity, MyUtils.GetRandomPerpendicularVector(ref gravity), gravity); } } }
public override void UpdateAfterSimulation() { base.UpdateAfterSimulation(); // DA: Consider using havok fields (buoyancy demo) for gravity of planets. Physics.RigidBody.Gravity = MyGravityProviderSystem.CalculateGravityInPointForGrid(PositionComp.GetPosition()); }