コード例 #1
0
 // Add force to an existing velocity affector
 public void AddVelocityAffector(PhysicPointModel model, string key, FixedVector3 affectorValue)
 {
     if (StateManager.state.IsPostUpdating)
     {
         if (model.velocityAffectors.ContainsKey(key))
         {
             model.velocityAffectors[key] += affectorValue;
         }
         else
         {
             model.velocityAffectors[key] = affectorValue;
         }
     }
     else
     {
         if (affectorsIncremented.ContainsKey(key))
         {
             affectorsIncremented[key] += affectorValue;
         }
         else
         {
             affectorsIncremented[key] = affectorValue;
         }
     }
 }
コード例 #2
0
        // Note: objects over elevators may behave in a weird way if gravity isn't enough to keep them grounded
        // with increased gravity or slower elevators everything seems smoother
        protected void KillGravityEffectAgainstPlane(PhysicWorldModel world, PhysicPointModel pointModel, PhysicPlaneModel planeModel)
        {
            FixedVector3 normal     = planeModel.normal;
            FixedVector3 defaultVel = pointModel.GetDefaultVelocityAffector();

            //FixedVector3 velToAdd = FixedVector3.Zero;
            if ((world.gravity.X < 0 && defaultVel.X < world.gravity.X && normal.X > 0) || (world.gravity.X > 0 && defaultVel.X > world.gravity.X && normal.X < 0))
            {
                defaultVel.X = world.gravity.X;
                //velToAdd.X = world.gravity.X - defaultVel.X;
            }

            if ((world.gravity.Y < 0 && defaultVel.Y < world.gravity.X && normal.Y > 0) || (world.gravity.Y > 0 && defaultVel.Y > world.gravity.Y && normal.Y < 0))
            {
                defaultVel.Y = world.gravity.Y;
                //velToAdd.Y = world.gravity.Y - defaultVel.Y;
            }

            if ((world.gravity.Z < 0 && defaultVel.Z < world.gravity.Z && normal.Z > 0) || (world.gravity.Z > 0 && defaultVel.Z > world.gravity.Z && normal.Z < 0))
            {
                defaultVel.Z = world.gravity.Z;
                //velToAdd.Z = world.gravity.Z - defaultVel.Z;
            }

            //UnityEngine.Debug.Log("Setting default velocity affector: " + defaultVel);
            pointModel.velocityAffectors[PhysicPointModel.defaultVelocityAffectorName] = defaultVel;
            //SetDefaultVelocityAffector(defaultVel);
            //AddDefaultVelocityAffector(velToAdd);
        }
コード例 #3
0
        // Update the input velocity affector multiplying input axis and max input velocity
        private static void UpdateInputVelocityAffector(GameEntityModel model)
        {
            PhysicPointModel pointModel = GetPointModel(model);

            if (pointModel == null)
            {
                return;
            }
            FixedVector3 newInputVel = FixedVector3.Zero;

            if (model.maxInputVelocity.X != 0 || model.maxInputVelocity.Y != 0)
            {
                Model inputModel = GetInputProvider(model);
                if (inputModel == null)
                {
                    return;
                }
                GameEntityInputProvider inputController = inputModel.Controller() as GameEntityInputProvider;
                if (inputController == null)
                {
                    return;
                }
                FixedVector3 axis = inputController.GetInputAxis(inputModel);
                newInputVel = new FixedVector3(axis.X * model.maxInputVelocity.X, axis.Y * model.maxInputVelocity.Y, axis.Z * model.maxInputVelocity.Z);
            }
            pointModel.velocityAffectors[inputVelocityAffector] = newInputVel;
        }
コード例 #4
0
        public bool CollisionCollisionCheck(FixedVector3 offset, bool facingRight, FrameData other, FixedVector3 otherOffset, bool otherFacingRight)
        {
            if (collisions.Count == 0 || other.collisions.Count == 0)
            {
                return(false);
            }

            Box offsettedBox      = OffsettedBox(collisionBoundingBox, offset, facingRight);
            Box otherOffsettedBox = OffsettedBox(other.collisionBoundingBox, otherOffset, otherFacingRight);

            if (offsettedBox.Intersects(otherOffsettedBox))
            {
                if (collisions.Count == 1 && other.collisions.Count == 1)
                {
                    return(true);
                }

                foreach (CollisionBox collisionBox in collisions)
                {
                    offsettedBox = OffsettedBox(collisionBox.box, offset, facingRight);
                    foreach (CollisionBox otherCollisionBox in other.collisions)
                    {
                        otherOffsettedBox = OffsettedBox(otherCollisionBox.box, otherOffset, otherFacingRight);
                        if (offsettedBox.Intersects(otherOffsettedBox))
                        {
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
コード例 #5
0
 public void SetPoints(FixedVector3 point1, FixedVector3 point2)
 {
     _x1Field.text = "" + (point1.X * 15);
     _y1Field.text = "" + (point1.Y * 15);
     _z1Field.text = "" + (point1.Z * 15);
     _x2Field.text = "" + ((point1.X - point2.X) * 15);
     _y2Field.text = "" + ((point1.Y - point2.Y) * 15);
     _z2Field.text = "" + ((point1.Z - point2.Z) * 15);
 }
コード例 #6
0
 // Constructor based on hit-collision intersection
 public HitInformation(HitData data, Box hitBox, int collisionId, Box collisionBox)
 {
     this.hitData     = data;
     this.collisionId = collisionId;
     intersection     = new Box(
         FixedVector3.Max(hitBox.pointOne, collisionBox.pointOne),
         FixedVector3.Min(hitBox.pointTwo, collisionBox.pointTwo)
         );
 }
コード例 #7
0
        // Compute the intersection point against a line segment
        public static bool CheckIntersection(PhysicPlaneModel planeModel, PhysicPointModel pointModel, out FixedVector3 intersection)
        {
            // plane may be moving, sum velocity to initial point position
            FixedVector3 pos1 = pointModel.lastPosition;
            FixedVector3 pos2 = pointModel.position;

            pos1 += planeModel.GetVelocity();
            return(CheckIntersection(planeModel, pos1, pos2, pointModel.stepTolerance, out intersection));
        }
コード例 #8
0
        public HitInformation HitCollisionCheck(
            FixedVector3 offset, bool facingRight,
            FrameData other, FixedVector3 otherOffset, bool otherFacingRight,
            List <AnimationHittenEntities> hittenEntities,
            ModelReference targetEntityId
            )
        {
            if (hits.Count == 0 || other.collisions.Count == 0)
            {
                return(null);
            }
            if (hits.Count == 1 &&
                hittenEntities != null &&
                hittenEntities.Count > hits[0].hitData.hitboxID &&
                hittenEntities[hits[0].hitData.hitboxID].entities.Find(x => x == targetEntityId) != null
                )
            {
                // already hit this entity
                return(null);
            }

            Box offsettedBox      = OffsettedBox(hitBoundingBox, offset, facingRight);
            Box otherOffsettedBox = OffsettedBox(other.collisionBoundingBox, otherOffset, otherFacingRight);

            if (offsettedBox.Intersects(otherOffsettedBox))
            {
                if (hits.Count == 1 && other.collisions.Count == 1)
                {
                    return(new HitInformation(hits[0].hitData, offsettedBox, other.collisions[0].collisionId, otherOffsettedBox));
                }
                foreach (HitBox hitBox in hits)
                {
                    // Check if this hit already hit this entity
                    if (hittenEntities != null &&
                        hittenEntities.Count > hitBox.hitData.hitboxID &&
                        hittenEntities[hitBox.hitData.hitboxID].entities.Find(x => x == targetEntityId) != null
                        )
                    {
                        // already hit this entity
                        continue;
                    }

                    // Check collisions against each collision box of the entity
                    offsettedBox = OffsettedBox(hitBox.box, offset, facingRight);
                    foreach (CollisionBox collisionBox in other.collisions)
                    {
                        otherOffsettedBox = OffsettedBox(collisionBox.box, otherOffset, otherFacingRight);
                        if (offsettedBox.Intersects(otherOffsettedBox))
                        {
                            return(new HitInformation(hitBox.hitData, offsettedBox, collisionBox.collisionId, otherOffsettedBox));
                        }
                    }
                }
            }
            return(null);
        }
コード例 #9
0
 // Set a velocity affector (force)
 public void SetVelocityAffector(PhysicPointModel model, string key, FixedVector3 affectorValue)
 {
     if (StateManager.state.IsPostUpdating)
     {
         model.velocityAffectors[key] = affectorValue;
         affectorsChanged.Remove(key);
     }
     else
     {
         affectorsChanged[key] = affectorValue;
     }
 }
コード例 #10
0
        public FixedVector3 GetPoint2()
        {
            float x, y, z;

            StringFieldUtils.TryEvaluate(_x2Field.text, out x);
            StringFieldUtils.TryEvaluate(_y2Field.text, out y);
            StringFieldUtils.TryEvaluate(_z2Field.text, out z);
            x /= 15; y /= 15; z /= 15;
            FixedVector3 p1 = GetPoint1();

            x = (float)p1.X - x; y = (float)p1.Y - y; z = (float)p1.Z - z;
            return(new FixedVector3(x, y, z));
        }
コード例 #11
0
 // Teleport to a new position
 public void SetPosition(PhysicPlaneModel model, FixedVector3 newPos)
 {
     if (StateManager.state.IsPostUpdating)
     {
         model.lastOriginPosition = model.origin = newPos;
         hasNewPosition           = false;
     }
     else
     {
         newPosition    = newPos;
         hasNewPosition = true;
     }
 }