public GameObject SpawnDebris(string part) { if (RigidModel != null && RigidModel.Parts.TryGetValue(part, out var srcpart)) { var newpart = srcpart.Clone(); var newmodel = new RigidModel() { Root = newpart, AllParts = new[] { newpart }, MaterialAnims = RigidModel.MaterialAnims, Path = newpart.Path, }; srcpart.Active = false; var tr = srcpart.LocalTransform * GetTransform(); var obj = new GameObject($"{Name}$debris-{part}", newmodel, Resources); obj.Transform = tr; obj.World = World; obj.World.Objects.Add(obj); var pos0 = Vector3.Transform(Vector3.Zero, GetTransform()); var pos1 = Vector3.Transform(Vector3.Zero, tr); var vec = (pos1 - pos0).Normalized(); var initialforce = 100f; var mass = 50f; if (CollisionGroups != null) { var cg = CollisionGroups.FirstOrDefault(x => x.obj.Equals(part, StringComparison.OrdinalIgnoreCase)); if (cg != null) { mass = cg.Mass; initialforce = cg.ChildImpulse; } } PhysicsComponent.ChildDebris(obj, srcpart, mass, vec * initialforce); } return(null); }
public GameObject SpawnDebris(string part) { if (CmpParts == null) { return(null); } for (int i = 0; i < CmpParts.Count; i++) { var p = CmpParts[i]; if (p.ObjectName.Equals(part, StringComparison.OrdinalIgnoreCase)) { var tr = p.GetTransform(GetTransform()); CmpParts.RemoveAt(i); var obj = new GameObject(p.Model, Resources, RenderComponent != null, false); obj.Transform = tr; obj.World = World; obj.World.Objects.Add(obj); var pos0 = GetTransform().Transform(Vector3.Zero); var pos2 = p.GetTransform(GetTransform()).Transform(Vector3.Zero); var vec = (pos2 - pos0).Normalized(); var initialforce = 100f; var mass = 50f; if (CollisionGroups != null) { var cg = CollisionGroups.FirstOrDefault(x => x.obj.Equals(part, StringComparison.OrdinalIgnoreCase)); if (cg != null) { mass = cg.Mass; initialforce = cg.ChildImpulse; } } PhysicsComponent.ChildDebris(obj, p, mass, vec * initialforce); return(obj); } } return(null); }