/// ----------------------------------------------- /// PRECACHED MEDIA /// ----------------------------------------------- private static string ClassName = "AlienModelLoader"; private static bool HasCached = false; /// static public int StaticRigidActorPointer = MPrecacher.PrecacheActorPointer(ClassName, "Alien_RagDoll.xml"); static public RigidActorAnimated StaticRigidActor;
/// <summary> /// does precaching of resources and statics initialization /// </summary> private static bool initStatics = false; public static void Precache() { // one-time init of particular vars & media if (!initStatics) { initStatics = true; HasCached = MPrecacher.Precache(ClassName, HasCached); StaticRigidActor = (RigidActorAnimated)MActor.GetFromPointer(StaticRigidActorPointer); StaticRigidActor.GhostObject = true; StaticRigidActor.CreateFramesList(); StaticRigidActor.StopPhysicsControl(); ...
public static void SetupPlayer(PlayerBase player) { player.MyRigidActor = (RigidActorAnimated)MActor.CloneFromPointer(player.MyWorld, StaticRigidActorPointer); player.MyRigidActor.StaticModelToUse = StaticRigidActor.MyModel; player.MyRigidActor.CreateFramesList(); player.MyRigidActor.StopPhysicsControl(); player.MyRigidActor.IsHidden = true; player.MyRigidActor.AutoUpdateModelTransformation = false; player.MyRigidActor.UpdateMyModelLighting = false; player.MyRigidActor.Parent = player; player.MyModel = player.MyRigidActor.MyModel; ...
/// <summary> /// RigidActor used as the RagDoll and for this Player's MyModel /// </summary> public RigidActorAnimated MyRigidActor;
protected void ActivateRagdoll() { if (MHelpers.IsDedicated()) return; MyRigidActor.Location = Location; MyRigidActor.Rotation = newRot; MyRigidActor.StartPhysicsControl(); } protected void DeactivateRagdoll() { if (MHelpers.IsDedicated()) return; MyRigidActor.StopPhysicsControl(); }
protected override void DisposeResources() { /// Normally we wouldn't nullify MyModel upon disposal, /// but we know this MyModel is also owned by our RigidActor, /// so we'll let the RigidActor dispose of it MyModel = null; if (MyRigidActor != null) { MyRigidActor.Destroy(); MyRigidActor = null; } ...
Player ctor: AutoUpdateModelTransformation = false; Player PreRender: public override void PreRender(MCamera camera) { // if not dead, update the model's transformation according to the Player's Rotation if (!IsDead()) { .... // Finally update the Player's Model which will increment its animations // and apply all the hierarchial transformations MyModel.Update(); } }
protected void ActivateRagdoll() { if (MHelpers.IsDedicated()) return; // we should clear any custom bone influences before activating our ragdoll MyModel.SetFrameInfluence(spineBone, MHelpers.IdentityMatrix); MyRigidActor.Location = Location; MyRigidActor.Rotation = newRot; MyRigidActor.StartPhysicsControl(); MVector velocity = Velocity; float totalMass = MyRigidActor.TotalMass; if(velocity.Length() < 7) MyRigidActor.ApplyImpulseToFrame("Bip01_Pelvis", velocity * totalMass, Location); if (deathImpulseAmount > 0) MyRigidActor.ApplyImpulseToClosestFrame(deathImpulseAmount / 42.0f * totalMass, deathImpactPoint); }