/// <summary>Overridden from <see cref="Engine.EntitySystem.Entity.OnPostCreate(Boolean)"/>.</summary> protected override void OnPostCreate(bool loaded) { base.OnPostCreate(loaded); pathFindWaitTime = World.Instance.Random.NextFloat(); CreatePhysicsModel(); Body body = PhysicsModel.CreateBody(); mainBody = body; body.Name = "main"; body.Static = true; body.Position = Position; body.Rotation = Rotation; float length = Type.Height - Type.Radius * 2; if (length < 0) { Log.Error("Length < 0"); return; } CapsuleShape shape = body.CreateCapsuleShape(); shape.Length = length; shape.Radius = Type.Radius; shape.ContactGroup = (int)ContactGroup.Dynamic; AddTimer(); //!!!!!need? //for update in GridPathFindSystem Vec3 p = Position; Position = p; PhysicsModel.PushToWorld(); if (mainBody != null) { oldMainBodyPosition = mainBody.Position; } }
void UpdatePhysicsModel() { DestroyPhysicsModel(); if (active) { CreatePhysicsModel(); Body body = PhysicsModel.CreateBody(); body.Static = true; body.SetTransform(Position, Rotation); BoxShape shape = body.CreateBoxShape(); shape.ContactGroup = (int)ContactGroup.Dynamic; // Static; shape.Dimensions = Scale; body.PushedToWorld = true; } }
/// <summary>Overridden from <see cref="Engine.EntitySystem.Entity.OnPostCreate(Boolean)"/>.</summary> protected override void OnPostCreate(bool loaded) { base.OnPostCreate(loaded); SetTurnToPosition(Position + Rotation.GetForward() * 100); CreatePhysicsModel(); Body body = PhysicsModel.CreateBody(); mainBody = body; body.Name = "main"; body.Position = Position; body.Rotation = Rotation; body.Sleepiness = 0; body.LinearVelocity = linearVelocityForSerialization; float length = Type.Height - Type.Radius * 2 - Type.WalkUpHeight; if (length < 0) { length = 2.5f; //Log.Error("Length < 0"); //return; } //Bone headbone = null; MapObjectAttachedHelper Headhelper = GetFirstAttachedObjectByAlias("Head") as MapObjectAttachedHelper; //MapObjectAttachedMesh mainMesh = GetFirstAttachedObjectByAlias("Main") as MapObjectAttachedMesh; //foreach (Bone BN in mainMesh.MeshObject.Mesh.Skeleton.Bones) //{ // if (BN.Name == "ValveBiped_forward") // { // headbone = BN; // break; // } //} ////create Head Sphear //{ // Body head = PhysicsModel.CreateBody(); // head.Name = "HeadBody"; // head.Position = Position + new Vec3(0, 0, 2f); // head.Rotation = Rotation; // body.Sleepiness = 0; // body.LinearVelocity = linearVelocityForSerialization; { SphereShape shape = body.CreateSphereShape(); shape.Radius = 0.2f; shape.ContactGroup = (int)ContactGroup.Dynamic; shape.StaticFriction = 0; shape.DynamicFriction = 0; shape.Hardness = 0; shape.Name = "Head"; if (Headhelper != null) { shape.Position = Headhelper.PositionOffset; } //if (headbone != null) //{ // shape.Position = headbone.Position; //} } //} //create main capsule { CapsuleShape shape = body.CreateCapsuleShape(); shape.Length = length; shape.Radius = Type.Radius; shape.ContactGroup = (int)ContactGroup.Dynamic; shape.StaticFriction = 0; shape.DynamicFriction = 0; //shape.Bounciness = 0; shape.Hardness = 0; float r = shape.Radius; shape.Density = Type.Mass / (MathFunctions.PI * r * r * shape.Length + (4.0f / 3.0f) * MathFunctions.PI * r * r * r); shape.SpecialLiquidDensity = .5f; shape.Name = "main"; } //create down capsule { CapsuleShape shape = body.CreateCapsuleShape(); shape.Length = Type.Height - Type.BottomRadius * 2; shape.Radius = Type.BottomRadius; shape.Position = new Vec3(0, 0, (Type.Height - Type.WalkUpHeight) / 2 - Type.Height / 2); shape.ContactGroup = (int)ContactGroup.Dynamic; //shape.Bounciness = 0; shape.Hardness = 0; shape.Density = 0; shape.SpecialLiquidDensity = .5f; shape.Name = "down"; shape.StaticFriction = 0; shape.DynamicFriction = 0; } PhysicsModel.PushToWorld(); AddTimer(); }
/// <summary>Overridden from <see cref="Engine.EntitySystem.Entity.OnPostCreate(Boolean)"/>.</summary> protected override void OnPostCreate(bool loaded) { base.OnPostCreate(loaded); SetTurnToPosition(Position + Rotation.GetForward() * 100); CreatePhysicsModel(); Body body = PhysicsModel.CreateBody(); mainBody = body; body.Name = "main"; body.Position = Position; body.Rotation = Rotation; body.Sleepiness = 0; body.LinearVelocity = linearVelocityForSerialization; body.AngularDamping = 10; body.CenterOfMassPosition = new Vec3(0, 0, -Type.Height / 4); body.MassMethod = Body.MassMethods.Manually; body.Mass = Type.Mass; body.InertiaTensorFactor = new Vec3(100, 100, 100); body.PhysX_SolverPositionIterations = 1; float length = Type.Height - Type.Radius * 2 - Type.WalkUpHeight; if (length < 0) { Log.Error("Character: OnPostCreate: Type.Height - Type.Radius * 2 - Type.WalkUpHeight < 0."); return; } //create main capsule { CapsuleShape shape = body.CreateCapsuleShape(); shape.Length = length; shape.Radius = Type.Radius; shape.ContactGroup = (int)ContactGroup.Dynamic; shape.StaticFriction = 0; shape.DynamicFriction = 0; shape.Restitution = 0; shape.Hardness = 0; shape.SpecialLiquidDensity = 1500; } //create bottom capsule { CapsuleShape shape = body.CreateCapsuleShape(); shape.Length = Type.Height - Type.BottomRadius * 2; shape.Radius = Type.BottomRadius; shape.Position = new Vec3(0, 0, (Type.Height - Type.WalkUpHeight) / 2 - Type.Height / 2); shape.ContactGroup = (int)ContactGroup.Dynamic; shape.StaticFriction = 0; shape.DynamicFriction = 0; shape.Restitution = 0; shape.Hardness = 0; shape.SpecialLiquidDensity = 1500; } PhysicsModel.PushToWorld(); PhysicsWorld.Instance.MainScene.PostStep += MainScene_PostStep; SubscribeToTickEvent(); }
/// <summary>Overridden from <see cref="Engine.EntitySystem.Entity.OnPostCreate(Boolean)"/>.</summary> protected override void OnPostCreate(bool loaded) { base.OnPostCreate(loaded); SetTurnToPosition(Position + Rotation.GetForward() * 100); CreatePhysicsModel(); Body body = PhysicsModel.CreateBody(); mainBody = body; body.Name = "main"; body.Position = Position; body.Rotation = Rotation; body.Sleepiness = 0; body.LinearVelocity = linearVelocityForSerialization; float length = Type.Height - Type.Radius * 2 - Type.WalkUpHeight; if (length < 0) { Log.Error("Length < 0"); return; } //create main capsule { CapsuleShape shape = body.CreateCapsuleShape(); shape.Length = length; shape.Radius = Type.Radius; shape.ContactGroup = (int)ContactGroup.Dynamic; shape.StaticFriction = 0; shape.DynamicFriction = 0; shape.Bounciness = 0; shape.Hardness = 0; float r = shape.Radius; shape.Density = Type.Mass / (MathFunctions.PI * r * r * shape.Length + (4.0f / 3.0f) * MathFunctions.PI * r * r * r); shape.SpecialLiquidDensity = .5f; } //create down capsule { CapsuleShape shape = body.CreateCapsuleShape(); shape.Length = Type.Height - Type.BottomRadius * 2; shape.Radius = Type.BottomRadius; shape.Position = new Vec3(0, 0, (Type.Height - Type.WalkUpHeight) / 2 - Type.Height / 2); shape.ContactGroup = (int)ContactGroup.Dynamic; shape.Bounciness = 0; shape.Hardness = 0; shape.Density = 0; shape.SpecialLiquidDensity = .5f; shape.StaticFriction = 0; shape.DynamicFriction = 0; } PhysicsModel.PushToWorld(); AddTimer(); }