Esempio n. 1
0
        /// <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);
            if (PhysicsModel != null)
            {
                PhysicsModel.PopFromWorld();

                Damager_Ball        = PhysicsModel.GetBody("Damager_Ball");
                Damager_Ball_Player = PhysicsModel.GetBody("CT");

                //if (Damager_Ball_Player != null)
                //{
                //    //this.Type.BallRadius = .5f;//((Damager_Ball_Player.Shapes[0].Volume * 3f) / (4f * (float)Math.PI) * .333333f);
                //    foreach (Body body in PhysicsModel.Bodies)
                //        body.Collision += new Body.CollisionDelegate(body_Collision);
                //}

                if (!EntitySystemWorld.Instance.IsEditor())
                {
                    Damager_Ball_Player.Shapes[0].Density              = PhysicsDensity;
                    Damager_Ball_Player.Shapes[0].DynamicFriction      = PhysicsDynamicFriction;
                    Damager_Ball_Player.Shapes[0].Restitution          = PhysicsBounciness; //Bounciness
                    Damager_Ball_Player.Shapes[0].StaticFriction       = PhysicsStaticFriction;
                    Damager_Ball_Player.Shapes[0].SpecialLiquidDensity = PhysicsLiquidDensity;
                    Damager_Ball_Player.Shapes[0].ContactGroup         = (int)ContactGroup.Dynamic;
                    Damager_Ball_Player.EnableGravity  = true;
                    Damager_Ball_Player.LinearVelocity = linearVelocityForSerialization;
                }

                if (!EntitySystemWorld.Instance.IsEditor())
                {
                    if (Damager_Ball_Player == null)
                    {
                        Log.Error("Damager_Ball.type: \"Damager_Ball\" body does not exist. The Physics Body is Named incorrectly?");
                    }
                }
                SubscribeToTickEvent();
                CheckPhysicsProperties();
                PhysicsModel.PushToWorld();
            }

            //Incin
            //if activeMaxTurrets turret was out from before RemoveMiniTurret it
            //if (turret != null)
            //{
            //    turret.SetForDeletion(false);
            //    turretTimer = 0; //reset remove timer
            //    activeturrets = 0;  //reset turret counts
            //}
        }
Esempio n. 2
0
        protected void CheckPhysicsProperties()
        {
            if (Damager_Ball_Player != null)
            {
                PhysicsModel.PopFromWorld();
                Damager_Ball_Player.Shapes[0].Density              = PhysicsDensity;
                Damager_Ball_Player.Shapes[0].DynamicFriction      = PhysicsDynamicFriction;
                Damager_Ball_Player.Shapes[0].Restitution          = PhysicsBounciness;//Bounciness
                Damager_Ball_Player.Shapes[0].StaticFriction       = PhysicsStaticFriction;
                Damager_Ball_Player.Shapes[0].SpecialLiquidDensity = PhysicsLiquidDensity;
                Damager_Ball_Player.Shapes[0].ContactGroup         = (int)ContactGroup.Dynamic;
                Damager_Ball_Player.EnableGravity = true;

                PhysicsModel.PushToWorld();
                //GameEngineApp.Instance.AddScreenMessage("Physics Updated");
            }
        }
Esempio n. 3
0
        /// <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;
            }
        }
        /// <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();
        }
Esempio n. 5
0
        /// <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();
        }
Esempio n. 6
0
        /// <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();
        }