Example #1
0
        public override IEnumerator Apply(EntityPlayer player, EntityAlive target, OptionEffect opt)
        {
            // TODO: randomize chance, and only on ice or snow ?
            // check is block below is snow
            Vector3 dir = Vectors.Float.Randomize(Zombiome.rand, 1f);

            dir   = dir.normalized;
            dir.y = 0.1f;
            Vector3i at = Vectors.ToInt(target.GetPosition());

            if (World.GetBlock(at).type == BlockValue.Air.type && World.GetBlock(at - Vectors.Up).type == BlockValue.Air.type)
            {
                yield break; // target is not on ground  // todo: snow only
            }
            Vector3 motion = EffectsEntity.MoveDir(target);

            if (motion.magnitude <= 0.3f)
            {
                yield break;
            }
            Vector3 slideDir = Vectors.Float.Randomize(rand, 1f, motion.normalized).normalized;

            slideDir.y = 0.05f;
            EntityMover mover = new EntityMover(2, 0.2f, 1); // .Config(1);

            yield return(mover.Move(target, slideDir));

            target.Buffs.AddBuff("buffRagdoll");
            if (target is EntityPlayerLocal)
            {
                GameManager.ShowTooltip((EntityPlayerLocal)target, "You slipped !");
            }
        }
Example #2
0
    public override void ExecuteUncatch(MinEventParams _params)
    {
        // Printer.Print("MinEventActionEject", _params.Self, _params.Other);
        if (CheckOthers && null == _params.Other)
        {
            return;                                       // bleeding would cause jumping infinitely
        }
        EntityMover mover;
        Vector3     dir;

        if (null != this.targets)
        {
            // Printer.Print("MinEventActionEject has targets", targets.Count);
            mover = new EntityMover((int)dsi[0], dsi[1], (int)dsi[2]);
            foreach (EntityAlive ent in this.targets)
            {
                dir = strength * Vectors.Float.Randomize(Zombiome.rand, dirrandom, Vectors.Float.UnitY);
                if (ent != null)
                {
                    mover.Apply(ent, dir);
                }
            }
            return;
        }
        mover = new EntityMover((int)dsi[0], dsi[1], (int)dsi[2]);
        dir   = strength * Vectors.Float.Randomize(Zombiome.rand, dirrandom, Vectors.Float.UnitY);
        if (_params.Self != null)
        {
            mover.Apply(_params.Self, dir);
        }
    }
Example #3
0
 public ObjectMover(BepuEntityObject entityObject, bool VelocityMotor)
 {
     bepuEntityObject = entityObject;
     mover            = new EntityMover(entityObject.Entity);
     rotator          = new EntityRotator(entityObject.Entity);
     if (VelocityMotor)
     {
         mover.LinearMotor.Settings.Mode = BEPUphysics.Constraints.TwoEntity.Motors.MotorMode.VelocityMotor;
     }
 }
Example #4
0
        public override IEnumerator Apply(EntityPlayer player, EntityAlive target, OptionEffect opt)
        {
            Zombiome.Routines.Start(Particles._Next(player), "Jumping-Particles");
            // EntityMover mover = new EntityMover(2, 0.2f, 1); // randomize
            SdtdUtils.EffectsItem.SpawnParticle(target.GetPosition(), "treeGib_birch_small", biome.groundColor);
            int         len   = 5 + (int)(this.rand.RandomFloat * 5);
            EntityMover mover = new EntityMover(len, 0.5f, 1); // tres bien : petit saut

            mover.Apply(target, Vectors.Float.UnitY);
            yield break;
        }
Example #5
0
 public void Push()
 {
     foreach (KeyValuePair <Entity, int> item in CollideH)
     {
         Vector3 dest = item.Key.GetPosition();
         dest   = new Vector3(dest.x, dest.y, dest.z);
         dest.y = Math.Max(dest.y, 1f * item.Value + 0.05f);
         EntityMover.Teleport(item.Key, dest, false);
     }
     CollideH.Clear();
 }
Example #6
0
        public void PostInitialise()
        {
            mover   = new EntityMover(physicsComponent.PhysicsEntity);
            rotator = new EntityRotator(physicsComponent.PhysicsEntity);
            SystemCore.PhysicsSimulation.Add(mover);
            SystemCore.PhysicsSimulation.Add(rotator);

            mover.LinearMotor.Settings.Servo.SpringSettings.Stiffness /= 10000;
            mover.LinearMotor.Settings.Servo.SpringSettings.Damping   /= 1000;

            e = ParentObject as SimpleEnemy;
        }
Example #7
0
    // Start is called before the first frame update
    void Start()
    {
        m_startingNode = m_grid.GetNode(Node.NodeType.PLAYER_SPAWN);
        Node.NodeType [] invalidNodeTypes = new Node.NodeType [] { Node.NodeType.WALL, Node.NodeType.VILLAIN_WALL };
        m_playerEntity     = new EntityMover(m_startingNode, EntityMover.Directions.RIGHT, invalidNodeTypes);
        transform.position = m_startingNode.WorldPosition;

        m_updatePositionCooler = 3.0f;

        // Reset transform scale
        transform.localScale = Vector3.one;
    }
Example #8
0
    public override void Execute(List <string> _params, CommandSenderInfo _senderInfo)
    {
        /*
         * Direction not perfect, always moving up, jumping diagonally (issue of not waiting callback ?)
         *
         */
        Entity target = GameManager.Instance.World.GetLocalPlayers()[0];

        if (_params.Count > 0 && _params[0] == "sg")
        {
            Vector3  pos  = target.GetPosition();
            Vector3i ipos = Vectors.ToInt(pos);
            Printer.Print("pos: ", pos, "=>", ipos, "=>", Vectors.ToFloat(ipos));
            Printer.Print("pos: ", ipos, "=>", Vectors.ToFloat(ipos), "=>", Vectors.ToInt(Vectors.ToFloat(ipos)));
            target.SetPosition(pos); // _MoveSetPos only
            return;
            // also check conversion in Emplacement
        }


        int     check = 0;
        int     eid   = -1;
        Vector3 dir   = Vectors.Float.UnitY;

        if (_params.Count > 0)
        {
            eid = int.Parse(_params[0]);
        }
        if (_params.Count > 1)
        {
            check = int.Parse(_params[1]);
        }
        if (_params.Count > 2)
        {
            dir = StringParsers.ParseVector3(_params[2]);
        }

        if (eid > 0)
        {
            target = GameManager.Instance.World.GetEntity(eid);
        }
        if (target == null)
        {
            Printer.Print("Entity not there ", eid); return;
        }

        Printer.Print("ConsoleCmdEMover", eid, check, dir);
        EntityMover mover = new EntityMover(3, 0.2f); // .Config(1);

        mover.checkCollision = check == 1;
        mover.Apply(target, dir); // This is a routine... so check not executed ...
    }
Example #9
0
    IEnumerator FlipCar()
    {
        EntityMover em       = GetComponent <EntityMover>();
        Animator    Animator = transform.GetComponentInChildren <Animator>();

        em.doMove = false;
        Animator.Play("Flip");
        yield return(new WaitForSecondsRealtime(Random.Range(0.5f, 3.5f)));

        Animator.Play("Idle");
        em.dist   = 0f;
        em.doMove = true;
    }
Example #10
0
        public override IEnumerator Apply(EntityPlayer player, EntityAlive target, OptionEffect opt)
        {
            if (target.Buffs.HasBuff(buff))
            {
                yield break;
            }
            Vector3     dir   = -0.5f * Vectors.Float.UnitY;
            EntityMover mover = new EntityMover(1); // .Config(1);

            yield return(mover.Move(target, dir));

            target.Buffs.AddBuff(buff);
        }
Example #11
0
        public void PostInitialise()
        {
            player = ParentObject as Player;
            this.physicsComponent = ParentObject.GetComponent <PhysicsComponent>();

            mover   = new EntityMover(physicsComponent.PhysicsEntity);
            rotator = new EntityRotator(physicsComponent.PhysicsEntity);
            SystemCore.PhysicsSimulation.Add(mover);
            SystemCore.PhysicsSimulation.Add(rotator);


            mover.LinearMotor.Settings.Servo.SpringSettings.Stiffness /= 10000;
            mover.LinearMotor.Settings.Servo.SpringSettings.Damping   /= 1000;
        }
        public ModelObjs(GameEngine GameEngine, Vector3 StartPosition) :
            base(GameEngine, GameEngine.Model_Items_ModelObjs, StartPosition)
        {
            XRotation_ModelOffset = -MathHelper.PiOver2;

            //ModelDataExtractor.GetVerticesAndIndicesFromModel(model, out staticTriangleVertices, out staticTriangleIndices);

            entity      = new Box(StartPosition, 1, 1, 1); //Set up Entity Mover
            entityMover = new EntityMover(entity);

            //Add Entities too Physics Sim
            vxEngine.Current3DSceneBase.BEPUPhyicsSpace.Add(entity);
            vxEngine.Current3DSceneBase.BEPUDebugDrawer.Add(entity);
            vxEngine.Current3DSceneBase.BEPUPhyicsSpace.Add(entityMover);
            SpecularIntensity = 100;
            SpecularPower     = 0.5f;
        }
        public WoodenCrate(GameEngine GameEngine, Vector3 StartPosition) :
            base(GameEngine, GameEngine.Model_Items_WoodenCrate, StartPosition)
        {
            //NormalMap = vxEngine.Game.Content.Load<Texture2D>("Models/items/wooden crate/crate_side_nm");
            XRotation_ModelOffset = -MathHelper.PiOver2;
            //Vector_ModelOffSet = new Vector3(-0.5f, 1 / 2, 0.5f);
            //entity = new Box(StartPosition - Vector_ModelOffSet, 1, 1, 1, 1000);

            entity      = new Box(StartPosition, 1, 1, 1); //Set up Entity Mover
            entityMover = new EntityMover(entity);

            //Add Entities too Physics Sim
            vxEngine.Current3DSceneBase.BEPUPhyicsSpace.Add(entity);
            vxEngine.Current3DSceneBase.BEPUDebugDrawer.Add(entity);
            vxEngine.Current3DSceneBase.BEPUPhyicsSpace.Add(entityMover);

            InitShaders();
        }
Example #14
0
        public ISpaceObject CreateJoint(BEPUphysics.Entities.Entity entity1, BEPUphysics.Entities.Entity entity2, Vector3 pos, Vector3 direction, Vector3 anchor)
        {
            // entity1 is us
            // entity2 is the main map we are attaching to
            Vector3 originalPos = entity1.Position;

            entity1.Position = pos;
            this.joint       = new NoRotationJoint(entity2, entity1);
            entity1.Position = originalPos;
            if (this.mover != null && this.mover.Space != null)
            {
                this.main.Space.Remove(this.mover);
            }
            this.mover = new EntityMover(entity1);
            this.main.Space.Add(this.mover);
            this.physicsUpdated(entity1.Mass, entity1.Volume);
            return(this.joint);
        }
Example #15
0
        protected override void Start(SystemRegistry registry)
        {
            _physics         = registry.GetSystem <PhysicsSystem>();
            _collider        = GameObject.GetComponent <Collider>();
            _entityMover     = new EntityMover(_collider.Entity);
            _spline          = new CardinalSpline3D();
            _spline.PreLoop  = MapBoundaryBehavior(_boundaryBehavior);
            _spline.PostLoop = MapBoundaryBehavior(_boundaryBehavior);

            Vector3 origin = Transform.Position;

            foreach (var offset in TargetOffsets.OrderBy(co => co.Time))
            {
                _spline.ControlPoints.Add(offset.Time, origin + offset.Offset);
            }

            _physics.AddObject(_entityMover);
            _elapsedPreActivationTime = PreActivateTime;
        }
Example #16
0
        public Teapot(GameEngine GameEngine, Vector3 StartPosition) :
            base(GameEngine, GameEngine.Model_Items_Teapot, StartPosition)
        {
            //NormalMap = vxEngine.Game.Content.Load<Texture2D>("Models/teapot/teapot_nm");
            //SpecularMap = vxEngine.Game.Content.Load<Texture2D>("Models/teapot/teapot_sm");
            XRotation_ModelOffset = -MathHelper.PiOver2;
            //Vector_ModelOffSet = new Vector3(-0.5f, 1 / 2, 0.5f);
            //entity = new Box(StartPosition - Vector_ModelOffSet, 1, 1, 1, 1000);

            entity      = new Box(StartPosition, 1, 1, 1); //Set up Entity Mover
            entityMover = new EntityMover(entity);

            //Add Entities too Physics Sim
            vxEngine.Current3DSceneBase.BEPUPhyicsSpace.Add(entity);
            vxEngine.Current3DSceneBase.BEPUDebugDrawer.Add(entity);
            vxEngine.Current3DSceneBase.BEPUPhyicsSpace.Add(entityMover);


            ModelDataExtractor.GetVerticesAndIndicesFromModel(vxModel.ModelMain, out staticTriangleVertices, out staticTriangleIndices);
        }
Example #17
0
    // Start is called before the first frame update
    void Start()
    {
        eventManager  = GetComponent <EventManager>();
        gravity       = GetComponent <Gravity>();
        gravityPoints = GetComponent <GravityPoints>();
        entityMover   = GetComponent <EntityMover>();
        entityRotator = GetComponent <EntityRotator>();

        // This grabs the gameobject within the player called playerRange,
        //  takes the script of that object in order to check whether an enemy is close or not.
        encounter = GameObject.Find("playerRange").GetComponent <EntityEncounter>();//~

        // Current input affecting movement
        // May differ fron actual movement in case of obstacles, being in the air, etc
        movement = Movement.Stopped;

        // Current input affecting direction
        // Likely matches actual direction, since turning around is not hindered by obstacles
        direction = Direction.Right;
    }
Example #18
0
        public ConcreteCube(GameEngine GameEngine, Vector3 StartPosition) :
            base(GameEngine, GameEngine.Model_Items_Concrete, StartPosition)
        {
            //NormalMap = vxEngine.Game.Content.Load<Texture2D>("Models/concrete_cube/texture_nm");
            //SpecularMap = vxEngine.Game.Content.Load<Texture2D>("Models/concrete_cube/texture_sm");
            XRotation_ModelOffset = -MathHelper.PiOver2;

            ModelDataExtractor.GetVerticesAndIndicesFromModel(vxModel.ModelMain, out staticTriangleVertices, out staticTriangleIndices);

            entity      = new Box(StartPosition, 1, 1, 1); //Set up Entity Mover
            entityMover = new EntityMover(entity);

            //Add Entities too Physics Sim
            vxEngine.Current3DSceneBase.BEPUPhyicsSpace.Add(entity);
            vxEngine.Current3DSceneBase.BEPUDebugDrawer.Add(entity);
            vxEngine.Current3DSceneBase.BEPUPhyicsSpace.Add(entityMover);
            SpecularIntensity = 1;

            GameEngine.Model_Items_Concrete.SetTexturePackLevel(vxEnumTextureQuality.Ultra);
        }
Example #19
0
 public void Update(float dt)
 {
     if (this.mover != null)
     {
         Entity parentEntity = this.Parent.Value.Target;
         if (parentEntity != null && parentEntity.Active)
         {
             Voxel       parentMap = parentEntity.Get <Voxel>();
             Voxel.Coord coord     = this.Coord;
             this.mover.TargetPosition = parentMap.GetAbsolutePosition(new Vector3(coord.X + 1.0f, coord.Y + 1.0f, coord.Z + 1.0f));
         }
         else
         {
             if (this.mover != null && this.mover.Space != null)
             {
                 this.main.Space.Remove(this.mover);
             }
             this.mover = null;
         }
     }
 }
Example #20
0
        public vxScaleCube(vxEngine vxEngine, Vector3 StartPosition) :
            base(vxEngine, vxEngine.Assets.Models.UnitBox, StartPosition)
        {
            entity = new Box(StartPosition, 1, 1, 1);

            //Set up Entity Mover
            entityMover = new EntityMover(entity);

            //Add Entities too Physics Sim
            vxEngine.Current3DSceneBase.BEPUPhyicsSpace.Add(entity);
            vxEngine.Current3DSceneBase.BEPUDebugDrawer.Add(entity);
            vxEngine.Current3DSceneBase.BEPUPhyicsSpace.Add(entityMover);
            //entity.CollisionInformation.CollisionRules.Personal = Physics.BEPU.CollisionRuleManagement.CollisionRule.NoSolver;

            CurrentSandboxLevel.Items.Add(this);

            //Reset the element indicies.
            CurrentSandboxLevel.SetElementIndicies();

            prePos = Position;

            Saveable = false;
        }
Example #21
0
        public override IEnumerator Apply(EntityPlayer player, EntityAlive target, OptionEffect opt)
        {
            Vector3 tpos = target.GetPosition();
            Vector3 s    = Geo3D.Surface(tpos);

            if (s.y <= 1)
            {
                yield break;
            }
            float dy = tpos.y - s.y;

            if (dy >= 0.5f)
            {
                yield break;
            }
            if (dy <= -0.5f)
            {
                yield break;
            }
            Vector3     dir   = -0.3f * Vectors.Float.UnitY;
            EntityMover mover = new EntityMover(1); // .Config(1);

            yield return(mover.Move(target, dir));
        }
Example #22
0
 public ObjectMover(BepuEntityObject entityObject)
 {
     bepuEntityObject = entityObject;
     mover            = new EntityMover(entityObject.Entity);
     rotator          = new EntityRotator(entityObject.Entity);
 }
        /// <summary>
        /// Constructs a new demo.
        /// </summary>
        /// <param name="game">Game owning this demo.</param>
        public CharacterPlaygroundDemo(DemosGame game)
            : base(game)
        {
            game.Camera.Position = new Microsoft.Xna.Framework.Vector3(-10, 7, 5);
            game.Camera.Yaw      = MathHelper.Pi;
            //Since this is the character playground, turn on the character by default.
            character.Activate();
            //Having the character body visible would be a bit distracting.
            character.CharacterController.Body.Tag = "noDisplayObject";

            //Load in mesh data for the environment.
            Vector3[] staticTriangleVertices;
            int[]     staticTriangleIndices;


            var playgroundModel = game.Content.Load <Model>("CharacterControllerTestTerrain");

            //This load method wraps the TriangleMesh.GetVerticesAndIndicesFromModel method
            //to output vertices of type StaticTriangleGroupVertex instead of TriangleMeshVertex or simply Vector3.
            ModelDataExtractor.GetVerticesAndIndicesFromModel(playgroundModel, out staticTriangleVertices, out staticTriangleIndices);
            var staticMesh = new StaticMesh(staticTriangleVertices, staticTriangleIndices, new AffineTransform(new Vector3(.01f, .01f, .01f), Quaternion.Identity, new Vector3(0, 0, 0)));

            staticMesh.Sidedness = TriangleSidedness.Counterclockwise;

            Space.Add(staticMesh);
            game.ModelDrawer.Add(staticMesh);



            //Add a spinning blade for the character to ram itself into.
            var fanBase  = new Cylinder(new Vector3(-13, .5f, 50), 1.1f, 1);
            var fanBlade = new Box(fanBase.Position + new Vector3(0, .8f, 0), 5, .1f, 1f, 5);
            var fanJoint = new RevoluteJoint(fanBase, fanBlade, (fanBase.Position + fanBlade.Position) * .5f, Vector3.Up);

            fanJoint.Motor.IsActive = true;
            fanJoint.Motor.Settings.VelocityMotor.GoalVelocity = 30;
            fanJoint.Motor.Settings.MaximumForce = 300;
            Space.Add(fanBase);
            Space.Add(fanBlade);
            Space.Add(fanJoint);

            //Add a bridge connecting the two towers.
            Vector3 startPosition = new Vector3(-19.3f, 10.5f - .25f, 23 - .85f);
            var     startPlatform = new Box(startPosition - new Vector3(0, 0, 2.2f), 4, .5f, 6);

            Space.Add(startPlatform);
            Vector3 offset       = new Vector3(0, 0, 1.7f);
            Box     previousLink = startPlatform;
            Vector3 position     = new Vector3();

            for (int i = 1; i <= 7; i++)
            {
                position = startPosition + offset * i;
                Box link = new Box(position, 3, .3f, 1.5f, 50);
                link.LinearDamping  = .1f;
                link.AngularDamping = .1f;
                Space.Add(link);
                Space.Add(new RevoluteJoint(previousLink, link, position - offset * .5f, Vector3.Right));

                previousLink = link;
            }
            var endPlatform = new Box(position - new Vector3(0, 0, -3.8f), 4, .5f, 6);

            Space.Add(endPlatform);

            Space.Add(new RevoluteJoint(previousLink, endPlatform, position + offset * .5f, Vector3.Right));


            //Add in a floating platform controlled by a curve to serve as an elevator.
            Entity movingEntity = new Box(new Vector3(-10, 0, -10), 3, 1, 3);

            var positionCurve = new CardinalSpline3D();

            positionCurve.PreLoop  = CurveEndpointBehavior.Mirror;
            positionCurve.PostLoop = CurveEndpointBehavior.Mirror;

            positionCurve.ControlPoints.Add(-1, new Vector3(-19.3f, 0, 43));
            positionCurve.ControlPoints.Add(0, new Vector3(-19.3f, 0, 43));
            positionCurve.ControlPoints.Add(2, new Vector3(-19.3f, 0, 43));
            positionCurve.ControlPoints.Add(3, new Vector3(-19.3f, 0, 43));
            positionCurve.ControlPoints.Add(4, new Vector3(-19.3f, 5, 43));
            positionCurve.ControlPoints.Add(5f, new Vector3(-19.3f, 10, 43));
            positionCurve.ControlPoints.Add(6f, new Vector3(-19.3f, 10, 43));
            positionCurve.ControlPoints.Add(8f, new Vector3(-19.3f, 10, 43));
            positionCurve.ControlPoints.Add(9f, new Vector3(-19.3f, 10, 43));

            elevatorMover = new EntityMover(movingEntity);
            Space.Add(elevatorMover);
            Space.Add(movingEntity);

            elevatorPath = positionCurve;

            //Add in another floating platform controlled by a curve for horizontal transport.
            movingEntity = new Box(new Vector3(-10, 0, -10), 2.5f, .5f, 2.5f);

            var platformCurve = new LinearInterpolationCurve3D();

            platformCurve.PreLoop  = CurveEndpointBehavior.Mirror;
            platformCurve.PostLoop = CurveEndpointBehavior.Mirror;

            platformCurve.ControlPoints.Add(0, new Vector3(-1.75f, 10, 21.5f));
            platformCurve.ControlPoints.Add(2, new Vector3(-1.75f, 10, 21.5f));
            platformCurve.ControlPoints.Add(5, new Vector3(-1.75f, 10, 15.5f));
            platformCurve.ControlPoints.Add(10, new Vector3(-19.3f, 10, 15.5f));
            platformCurve.ControlPoints.Add(12, new Vector3(-19.3f, 10, 15.5f));
            platformCurve.ControlPoints.Add(15, new Vector3(-25, 10, 15.5f));
            platformCurve.ControlPoints.Add(22, new Vector3(-25, 10, 38));
            platformCurve.ControlPoints.Add(23, new Vector3(-22.75f, 10, 38));
            platformCurve.ControlPoints.Add(25, new Vector3(-22.75f, 10, 38));

            //Make it spin too.  That'll be fun.  Or something.
            var platformRotationCurve = new QuaternionSlerpCurve();

            platformRotationCurve.PreLoop  = CurveEndpointBehavior.Mirror;
            platformRotationCurve.PostLoop = CurveEndpointBehavior.Mirror;
            platformRotationCurve.ControlPoints.Add(0, Quaternion.Identity);
            platformRotationCurve.ControlPoints.Add(15, Quaternion.Identity);
            platformRotationCurve.ControlPoints.Add(22, Quaternion.CreateFromAxisAngle(Vector3.Up, MathHelper.PiOver2));
            platformRotationCurve.ControlPoints.Add(25, Quaternion.CreateFromAxisAngle(Vector3.Up, MathHelper.PiOver2));

            platformMover   = new EntityMover(movingEntity);
            platformRotator = new EntityRotator(movingEntity);
            Space.Add(platformMover);
            Space.Add(platformRotator);
            Space.Add(movingEntity);

            platformPath            = platformCurve;
            platformOrientationPath = platformRotationCurve;

            //Add in a diving board.

            Box divingBoardBase  = new Box(new Vector3(-9, 10, 39.3f), 5, 1, 3);
            Box divingBoard      = new Box(divingBoardBase.Position + new Vector3(-2, 0, 3.5f), 1, .3f, 3, 5);
            var divingBoardJoint = new RevoluteJoint(divingBoardBase, divingBoard, divingBoard.Position + new Vector3(0, 0, -1.5f), Vector3.Right);

            divingBoardJoint.Motor.IsActive            = true;
            divingBoardJoint.Motor.Settings.Mode       = MotorMode.Servomechanism;
            divingBoardJoint.Motor.Settings.Servo.Goal = 0;
            divingBoardJoint.Motor.Settings.Servo.SpringSettings.StiffnessConstant = 5000;
            divingBoardJoint.Motor.Settings.Servo.SpringSettings.DampingConstant   = 0;

            Space.Add(divingBoardBase);
            Space.Add(divingBoard);
            Space.Add(divingBoardJoint);


            //Add a second diving board for comparison.

            Box divingBoard2      = new Box(divingBoardBase.Position + new Vector3(2, 0, 5f), 1, .3f, 6, 5);
            var divingBoardJoint2 = new RevoluteJoint(divingBoardBase, divingBoard2, divingBoard2.Position + new Vector3(0, 0, -3), Vector3.Right);

            divingBoardJoint2.Motor.IsActive            = true;
            divingBoardJoint2.Motor.Settings.Mode       = MotorMode.Servomechanism;
            divingBoardJoint2.Motor.Settings.Servo.Goal = 0;
            divingBoardJoint2.Motor.Settings.Servo.SpringSettings.StiffnessConstant = 10000;
            divingBoardJoint2.Motor.Settings.Servo.SpringSettings.DampingConstant   = 0;

            Space.Add(divingBoard2);
            Space.Add(divingBoardJoint2);

            //Add a seesaw for people to jump on.
            Box           seesawBase  = new Box(new Vector3(-7, .45f, 52), 1, .9f, .3f);
            Box           seesawPlank = new Box(seesawBase.Position + new Vector3(0, .65f, 0), 1.2f, .2f, 6, 3);
            RevoluteJoint seesawJoint = new RevoluteJoint(seesawBase, seesawPlank, seesawPlank.Position, Vector3.Right);

            Space.Add(seesawJoint);
            Space.Add(seesawBase);
            Space.Add(seesawPlank);

            Space.Add(new Box(seesawPlank.Position + new Vector3(0, 1.3f, 2), 1, 1, 1, 5));


            //Add in some boxes to bump and jump on.
            int   numColumns = 3;
            int   numRows    = 3;
            int   numHigh    = 3;
            float xSpacing   = 1.01f;
            float ySpacing   = 1.01f;
            float zSpacing   = 1.01f;

            for (int i = 0; i < numRows; i++)
            {
                for (int j = 0; j < numColumns; j++)
                {
                    for (int k = 0; k < numHigh; k++)
                    {
                        Space.Add(new Box(new Vector3(
                                              5 + xSpacing * i - (numRows - 1) * xSpacing / 2f,
                                              1.58f + k * (ySpacing),
                                              45 + zSpacing * j - (numColumns - 1) * zSpacing / 2f),
                                          .5f, .5f, .5f, 5));
                    }
                }
            }



            //Add a log to roll!
            //Make it a compound so some boxes can be added to let the player know it's actually spinning.
            CompoundBody log = new CompoundBody(new List <CompoundShapeEntry>()
            {
                new CompoundShapeEntry(new CylinderShape(4, 1.8f), Quaternion.CreateFromAxisAngle(Vector3.Forward, MathHelper.PiOver2), 20),
                new CompoundShapeEntry(new BoxShape(.5f, .5f, 3.7f), new Vector3(1.75f, 0, 0), 0),
                new CompoundShapeEntry(new BoxShape(.5f, 3.7f, .5f), new Vector3(1.75f, 0, 0), 0),
                new CompoundShapeEntry(new BoxShape(.5f, .5f, 3.7f), new Vector3(-1.75f, 0, 0), 0),
                new CompoundShapeEntry(new BoxShape(.5f, 3.7f, .5f), new Vector3(-1.75f, 0, 0), 0)
            }, 50);

            log.Position       = new Vector3(-14.5f, 10, 41);
            log.AngularDamping = 0;


            RevoluteJoint logJointA = new RevoluteJoint(divingBoardBase, log, log.Position + new Vector3(2.5f, 0, 0), Vector3.Right);
            RevoluteJoint logJointB = new RevoluteJoint(endPlatform, log, log.Position + new Vector3(-2.5f, 0, 0), Vector3.Right);

            Space.Add(logJointA);
            Space.Add(logJointB);

            Space.Add(log);


            //Put some planks to stand on that show various slopes.
            int numPads = 10;

            for (int i = 0; i < numPads; i++)
            {
                offset = new Vector3(0, 0, 4);
                Box   a     = new Box(new Vector3(i * 1.5f + 3.5f, 10, 24), 1.5f, 1, 4);
                Box   b     = new Box(new Vector3(i * 1.5f + 3.5f, 10, 24), 1.5f, 1, 4);
                float angle = -i * MathHelper.PiOver2 / numPads;
                b.Orientation = Quaternion.CreateFromAxisAngle(Vector3.Right, angle);
                b.Position   += offset * .5f + Vector3.Transform(offset * .5f, b.Orientation);

                Space.Add(a);
                Space.Add(b);
            }
        }
Example #24
0
 /// <summary>
 /// Applies a movement speed modifying effect, timeouts greater than 0 makes it so existing effects from the source are replaced by this new application
 /// </summary>
 /// <returns>the modifier id, can be used to revoke it manually</returns>
 public int ApplySpeedMod(EntityMover.SpeedModType type, Entity source, float timeOut = -1)
 {
     if (!mover)
         return -1;
     return mover.ApplySpeedMod (source, type, timeOut);
 }
Example #25
0
 public PlayerControl(Dictionary <Key, bool> keys, EntityMover entity, World <Chunk <Block>, Block> world)
 {
     this.keys   = keys;
     this.entity = entity;
     this.world  = world;
 }
Example #26
0
 void Awake()
 {
     Rigidbody rb = GetComponent<Rigidbody> ();
     if (rb) {
         rb.isKinematic = true;
         rb.useGravity = false;
     }
     world = GameWorld.Instance;
     world.Register (this);
     mover = GetComponent<EntityMover> ();
     audioSource = GetComponent<AudioSource> ();
     float rndFactor = StandardGameSettings.Get.entityPitchRandomization;
     audioSource.pitch = Random.Range (1f - rndFactor, 1f + rndFactor);
     audioSource.playOnAwake = false;
     audioSource.loop = true;
     OnAwake ();
 }
Example #27
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="modelManager"></param>
        /// <param name="descriptor"></param>
        /// <param name="scene"></param>
        /// <param name="entity"></param>
        public KinematicModel(PhysicsManager physicsManager, ModelDescriptor descriptor, Scene scene, Entity entity)
        {
            this.entity         = entity;
            this.physicsManager = physicsManager;
            this.scene          = scene;
            this.preTransform   = descriptor.ComputePreTransformMatrix();
            this.nodeCount      = scene.Nodes.Count;

            convexHulls = new BepuEntity[nodeCount];
            var transforms = new Matrix[nodeCount];

            animSnapshot = new Matrix[nodeCount];
            offsets      = new Vector3[nodeCount];

            movers   = new EntityMover[nodeCount];
            rotators = new EntityRotator[nodeCount];

            scene.ComputeAbsoluteTransforms(transforms);


            for (int i = 0; i < scene.Nodes.Count; i++)
            {
                var node = scene.Nodes[i];

                if (node.MeshIndex < 0)
                {
                    continue;
                }

                var mesh     = scene.Meshes[node.MeshIndex];
                var indices  = mesh.GetIndices();
                var vertices = mesh.Vertices
                               .Select(v2 => MathConverter.Convert(v2.Position))
                               .ToList();

                var ms        = new MotionState();
                var transform = transforms[i] * preTransform *entity.GetWorldMatrix(1);

                var p = transform.TranslationVector;
                var q = Fusion.Core.Mathematics.Quaternion.RotationMatrix(transform);

                ms.AngularVelocity = MathConverter.Convert(Vector3.Zero);
                ms.LinearVelocity  = MathConverter.Convert(Vector3.Zero);
                ms.Orientation     = MathConverter.Convert(q);
                ms.Position        = MathConverter.Convert(p);

                //	recenter shape :
                //	https://bepuphysics.codeplex.com/wikipage?title=Shape%20Recentering
                var offset      = BEPUVector3.Zero;
                var convexShape = new ConvexHullShape(vertices, out offset);
                var convexHull  = new BepuEntity(convexShape, 0);

                offsets[i] = MathConverter.Convert(offset);

                convexHull.Tag = entity;

                convexHulls[i] = convexHull;

                movers[i]   = new EntityMover(convexHull);
                rotators[i] = new EntityRotator(convexHull);

                physicsManager.PhysSpace.Add(convexHull);
                physicsManager.PhysSpace.Add(movers[i]);
                physicsManager.PhysSpace.Add(rotators[i]);
            }
        }
Example #28
0
        protected override void InitializeSpace()
        {
            Entity movingEntity;

            //The moving entity can be either kinematic or dynamic; the EntityMover/Rotator works for either.
            movingEntity = new Box(new Vector3(-10, 0, -10), 3, 1, 1);

            //We're going to use a speed-controlled curve that wraps another curve.
            //This is the internal curve.
            //Speed-controlled curves let the user specify speeds at which an evaluator
            //will move along the curve.  Non-speed controlled curves can move at variable
            //rates based on the interpolation.
            var wrappedPositionCurve = new CardinalSpline3D();

            //Since the endpoints don't overlap, just reverse direction when they're hit.
            //The default is wrapping around; if there's a distance between the starting
            //and ending endpoints, the entity will jump very quickly (smashing anything in the way).
            wrappedPositionCurve.PreLoop  = CurveEndpointBehavior.Mirror;
            wrappedPositionCurve.PostLoop = CurveEndpointBehavior.Mirror;

            //Start the curve up above the blocks.
            //There's two control points because the very first and very last control points
            //aren't actually reached by the curve in a CardinalSpline3D; they are used
            //to define the tangents on the interior points.
            wrappedPositionCurve.ControlPoints.Add(-1, new Vector3(0, 30, 0));
            wrappedPositionCurve.ControlPoints.Add(0, new Vector3(0, 20, 0));
            //Add a bunch of random control points to the curve.
            var random = new Random(0);

            for (int i = 1; i <= 10; i++)
            {
                wrappedPositionCurve.ControlPoints.Add(i, new Vector3(
                                                           (float)random.NextDouble() * 20 - 10,
                                                           (float)random.NextDouble() * 12,
                                                           (float)random.NextDouble() * 20 - 10));
            }

            positionPath = wrappedPositionCurve;

            //There's also a constant speed and variable speed curve type that can be used.
            //Try the following instead to move the entity at a constant rate:
            //positionPath = new ConstantLinearSpeedCurve(5, wrappedPositionCurve);

            var slerpCurve = new QuaternionSlerpCurve();

            slerpCurve.ControlPoints.Add(0, Quaternion.Identity);
            slerpCurve.ControlPoints.Add(1, Quaternion.CreateFromAxisAngle(Vector3.Up, MathHelper.PiOver2));
            slerpCurve.ControlPoints.Add(2, Quaternion.CreateFromAxisAngle(Vector3.Up, MathHelper.Pi));
            slerpCurve.ControlPoints.Add(3, Quaternion.CreateFromAxisAngle(Vector3.Up, 3 * MathHelper.PiOver2));
            slerpCurve.ControlPoints.Add(4, Quaternion.Identity);

            slerpCurve.PostLoop = CurveEndpointBehavior.Mirror;
            orientationPath     = slerpCurve;


            mover = new EntityMover(movingEntity);
            //Offset the place that the mover tries to reach a little.
            //Now, when the entity spins, it acts more like a hammer swing than a saw.
            mover.LocalOffset = new Vector3(3, 0, 0);
            rotator           = new EntityRotator(movingEntity);

            //Add the entity and movers to the space.
            Space.Add(movingEntity);
            Space.Add(mover);
            Space.Add(rotator);

            //Add some extra stuff to the space.
            Space.Add(new Box(new Vector3(0, -5, 0), 25, 10, 25));

            int   numColumns = 7;
            int   numRows    = 7;
            int   numHigh    = 3;
            float xSpacing   = 2.09f;
            float ySpacing   = 2.08f;
            float zSpacing   = 2.09f;

            for (int i = 0; i < numRows; i++)
            {
                for (int j = 0; j < numColumns; j++)
                {
                    for (int k = 0; k < numHigh; k++)
                    {
                        Space.Add(new Box(new Vector3(
                                              xSpacing * i - (numRows - 1) * xSpacing / 2,
                                              1.58f + k * (ySpacing),
                                              2 + zSpacing * j - (numColumns - 1) * zSpacing / 2),
                                          2, 2, 2, 10));
                    }
                }
            }
        }
Example #29
0
        // private int cursor = -1;
        public override void Effect1(EntityPlayer player, Emplacement place, OptionEffect opt)
        {
            Vector3 ppos = player.GetPosition();

            Vector3 where = place.position;
            Bounds area = new Bounds(ppos, new Vector3(40, 40, 40));

            EntityPool.Update(area);

            Vector3 sharedDir = place.direction;

            sharedDir.y = 0.2f;                           // Math.Abs(sharedDir.y); // TODO: constraint in Directions
            EntityMover mover = new EntityMover(3, 0.3f); // .Config(1);
            int         mode  = 0;                        // 0nothing, 1random, 2parralel, 3 player
            float       u     = rand.RandomFloat;

            if (u < 0.4f)
            {
                mode = 3;
            }
            else if (u < 0.6f)
            {
                mode = 2;
            }
            else if (u < 0.8f)
            {
                mode = 1;
            }

            foreach (Entity entity in EntityPool.Entities)
            {
                if (entity == null)
                {
                    continue;
                }
                // if (entity.IsDead()) continue;
                EntityAlive alive = (EntityAlive)entity;
                if (!alive.Buffs.HasBuff(opt.OptionEntity.buff))
                {
                    Printer.Log(40, "MovingGhost buffing", opt.OptionEntity.buff, alive);
                    alive.Buffs.AddBuff(opt.OptionEntity.buff);
                }
                Vector3 toward = Vectors.Float.Zero;
                if (false)
                {
                    if (mode == 3)
                    {
                        toward = (ppos - alive.GetPosition()).normalized;
                        // toward.y = rand.RandomRange(0.05f, 0.2f);
                        toward.y = 0.2f;
                    }
                    else if (u < 0.6)
                    {
                        toward = sharedDir;
                    }
                    else if (u < 0.8)
                    {
                        toward.x = rand.RandomRange(-1f, 1f);
                        toward.z = rand.RandomRange(-1f, 1f);
                        // toward.y = rand.RandomRange(0.05f, 0.2f);
                        toward   = toward.normalized;
                        toward.y = 0.2f;
                    }
                }
                toward = (ppos - alive.GetPosition()).normalized;
                // toward.y = rand.RandomRange(0.05f, 0.2f);
                toward.y = 0.2f;
                if (toward.magnitude > 0)
                {
                    // Can we have a single routine that manages all motions ?
                    Printer.Log(40, "MovingGhost motion", entity, toward);
                    Zombiome.Routines.Start(mover.Move(alive, toward), "MovingGhost");
                }
            }
        }