Beispiel #1
0
		// Release event may be accompained by a set animation event and set anchored position.
		// It safely releases at the relative position to parent, taking physics in consideration
		public static void ReleaseAnchoredEntity(GameEntityModel model, GameEntityModel anchoredEntityModel){
			int anchorId = -1;
			for (int i = 0; i < model.anchoredEntities.Count ; ++i){
				if (model.anchoredEntities[i] == anchoredEntityModel.Index){
					anchorId = i;
					break;
				}
			}
			if (anchorId == -1){
				// entity is not grabbed, return
				return;
			}
			anchoredEntityModel.parentEntity = new ModelReference();
			PhysicPointModel pointModel = GameEntityController.GetPointModel(anchoredEntityModel);
			if (pointModel != null){
				pointModel.isActive = true;
				PhysicPointModel parentPointModel = GameEntityController.GetPointModel(model);
				PhysicPointController pointController = pointModel.Controller() as PhysicPointController;
				if (pointController != null && parentPointModel != null){
					// Set position directly
					pointModel.position = parentPointModel.position;
					if (!model.IsFacingRight()) anchoredEntityModel.positionRelativeToParent.X *= -1;
					pointController.SetVelocityAffector(pointModel, PhysicPointController.setPositionffectorName, anchoredEntityModel.positionRelativeToParent);
					anchoredEntityModel.positionRelativeToParent = FixedVector3.Zero;
				}
			}
			model.anchoredEntities[anchorId] = new ModelReference();
		}
Beispiel #2
0
		// Anchor a model to it
		public static void AnchorEntity(GameEntityModel model, GameEntityModel modelToBeAnchored, int anchorId){
			if (IsAnchored(modelToBeAnchored)){
				Debug.LogWarning("Trying to anchor an entity that is already anchored");
				return;
			}
			if (model.parentEntity != null && model.parentEntity == modelToBeAnchored.Index){
				Debug.LogWarning("Cyclic anchoring attempt");
				return;
			}
			if (model.anchoredEntities == null) model.anchoredEntities = new List<ModelReference>(anchorId);
			while (model.anchoredEntities.Count <= anchorId) {
				model.anchoredEntities.Add(null);
			}
			if (model.anchoredEntities[anchorId] != null && model.anchoredEntities[anchorId] != ModelReference.InvalidModelIndex){
				Debug.LogWarning("Trying to anchor an entity to a busy anchor");
				return;
			}
			model.anchoredEntities[anchorId] = modelToBeAnchored.Index;
			modelToBeAnchored.parentEntity = model.Index;
			modelToBeAnchored.positionRelativeToParent = FixedVector3.Zero;
			PhysicPointModel pointModel = GameEntityController.GetPointModel(modelToBeAnchored);
			if (pointModel != null){
				pointModel.isActive = false;
			}
		}
Beispiel #3
0
        // Filter hit by hitter entity location
        private static GameEntityModel getHitEntityIfConformingOrientationOptions(HitInformation hit, OrientationOptions orientationOptions, GameEntityModel model)
        {
            GameEntityModel hitterModel = StateManager.state.GetModel(hit.entityId) as GameEntityModel;

            if (orientationOptions == OrientationOptions.any)
            {
                return(hitterModel);
            }

            PhysicPointModel modelPoint  = GameEntityController.GetPointModel(model);
            PhysicPointModel hitterPoint = GameEntityController.GetPointModel(hitterModel);
            bool             isFrontal;

            if (model.IsFacingRight())
            {
                isFrontal = hitterPoint.position.X >= modelPoint.position.X;
            }
            else
            {
                isFrontal = hitterPoint.position.X <= modelPoint.position.X;
            }
            if (isFrontal == (orientationOptions == OrientationOptions.fromFront))
            {
                return(hitterModel);
            }
            return(null);
        }
Beispiel #4
0
        // ----------------------
        // Ground and Wall checks

        public static bool IsGrounded(GameEntityModel model)
        {
            PhysicPointModel pointModel = GameEntityController.GetPointModel(model);

            if (pointModel == null)
            {
                return(false);
            }
            return(PhysicPointController.IsGrounded(pointModel));
        }
Beispiel #5
0
        // Apply a force on the physics velocity affector
        public static FixedFloat GetVerticalImpulse(GameEntityModel model)
        {
            PhysicPointModel pointModel = GameEntityController.GetPointModel(model);

            if (pointModel == null)
            {
                return(FixedFloat.Zero);
            }
            return(pointModel.velocityAffectors[PhysicPointModel.defaultVelocityAffectorName].Y);
        }
Beispiel #6
0
        public static FixedFloat CollisionZForce(GameEntityModel model)
        {
            PhysicPointModel pointModel = GameEntityController.GetPointModel(model);

            if (pointModel == null)
            {
                return(FixedFloat.Zero);
            }
            return(FixedFloat.Abs(pointModel.collisionInpact.Z));
        }
Beispiel #7
0
        public static bool IsHittingFarWall(GameEntityModel model)
        {
            PhysicPointModel pointModel = GameEntityController.GetPointModel(model);

            if (pointModel == null)
            {
                return(false);
            }
            return(pointModel.collisionInpact.Z > 0);
        }
Beispiel #8
0
		// Anchor a model to it, and optionally move the parent relative to the entity being anchored (e.g. move back a little when grabbing)
		public static void AnchorEntity(GameEntityModel model, GameEntityModel modelToBeAnchored, int anchorId, FixedVector3 deltaPosRelativeToAnched){
			AnchorEntity(model, modelToBeAnchored, anchorId);
			PhysicPointModel pointModel = GameEntityController.GetPointModel(model);
			PhysicPointModel anchoredPointModel = GameEntityController.GetPointModel(modelToBeAnchored);
			if (pointModel != null && anchoredPointModel != null){
				PhysicPointController pointController = pointModel.Controller() as PhysicPointController;
				if (pointController != null){
					if (!model.IsFacingRight()) deltaPosRelativeToAnched.X *= -1;
					FixedVector3 deltaPos = (anchoredPointModel.position + deltaPosRelativeToAnched) - pointModel.position;
					pointController.SetVelocityAffector(pointModel, PhysicPointController.setPositionffectorName, deltaPos);
				}
			}
		}
Beispiel #9
0
        // Safelly set position relative to self (e.g. vault), taking physics collisions in consideration
        public static void MoveEntity(GameEntityModel model, FixedVector3 relativePosition)
        {
            PhysicPointModel pointModel = GameEntityController.GetPointModel(model);

            if (pointModel != null)
            {
                PhysicPointController pointController = pointModel.Controller() as PhysicPointController;
                if (pointController != null)
                {
                    pointController.SetVelocityAffector(pointModel, PhysicPointController.setPositionffectorName, relativePosition);
                }
            }
        }
Beispiel #10
0
        // Set the velocity affector bound to animation velocity control
        public static void SetAnimationVelocity(GameEntityModel model, FixedVector3 velocity)
        {
            PhysicPointModel pointModel = GameEntityController.GetPointModel(model);

            if (pointModel == null)
            {
                return;
            }
            if (!model.IsFacingRight())
            {
                velocity.X *= -1;
            }
            pointModel.velocityAffectors[GameEntityController.animVelocityAffector] = velocity;
        }
Beispiel #11
0
        // Reset X and Z force components on the physics velocity affector
        public static void ResetPlanarImpulse(GameEntityModel model)
        {
            PhysicPointModel pointModel = GameEntityController.GetPointModel(model);

            if (pointModel == null)
            {
                return;
            }
            FixedVector3 originalImpulse;

            pointModel.velocityAffectors.TryGetValue(PhysicPointModel.defaultVelocityAffectorName, out originalImpulse);
            pointModel.velocityAffectors[PhysicPointModel.defaultVelocityAffectorName] =
                new FixedVector3(0, originalImpulse.Y, 0)
            ;
        }
Beispiel #12
0
        // Apply a force on the physics velocity affector
        public static void AddImpulse(GameEntityModel model, FixedVector3 impulse)
        {
            PhysicPointModel pointModel = GameEntityController.GetPointModel(model);

            if (pointModel == null)
            {
                return;
            }
            if (!model.IsFacingRight())
            {
                impulse.X *= -1;
            }
            pointModel.velocityAffectors[PhysicPointModel.defaultVelocityAffectorName] += impulse;
            //			pointModel.velocityAffectors[PhysicPointModel.defaultVelocityAffectorName] += new FixedVector3(0, impulse.Y, 0);
            //			pointModel.velocityAffectors[GameEntityController.animVelocityAffector] += new FixedVector3(impulse.X, 0, impulse.Z);
        }
        // Face to same direction as hitter is facing
        public static void FaceToHitterDirection(GameEntityModel model, bool oppositeFacing)
        {
            GameEntityController controller = model.Controller() as GameEntityController;
            PhysicPointModel     pointModel = GameEntityController.GetPointModel(model);

            if (pointModel != null && controller.lastHurts.Count > 0)
            {
                HitInformation  info   = controller.lastHurts[0];
                GameEntityModel hitter = StateManager.state.GetModel(info.entityId) as GameEntityModel;
                model.mIsFacingRight = hitter.IsFacingRight();
                if (oppositeFacing)
                {
                    model.mIsFacingRight = !model.IsFacingRight();
                }
            }
        }
Beispiel #14
0
        private static void SpawnAtIntersection(List <HitInformation> hits, GameEntityModel model, string prefabName, int lifetime, FixedVector3 offset, bool localSpace, ConvertGameToViewCoordinates gameToViewCoordinates)
        {
            GameObject selfObj = UnityObjectsPool.Instance.GetGameObject(model.Index);

            // For each hit, spawn randomly within the intersection box
            bool    spawnAtLeft;
            float   randomValue;
            Vector3 spawnLocation;

            foreach (HitInformation info in hits)
            {
                GameEntityModel otherModel = StateManager.state.GetModel(info.entityId) as GameEntityModel;
                if (otherModel != null)
                {
                    spawnAtLeft = !otherModel.IsFacingRight();
                    randomValue = UnityEngine.Random.Range(0f, 1f);
                    randomValue = randomValue * randomValue * randomValue;
                    if (spawnAtLeft)
                    {
                        randomValue = 1 - randomValue;
                    }
                    // Get a suitable location to spawn
                    spawnLocation.x = (float)(info.intersection.pointOne.X + (info.intersection.pointTwo.X - info.intersection.pointOne.X) * randomValue);
                    randomValue     = UnityEngine.Random.Range(0f, 1f);
                    randomValue     = 1 - (randomValue * randomValue);
                    randomValue    *= UnityEngine.Random.Range(0, 2) == 0 ? 0.5f : -0.5f;
                    spawnLocation.y = (float)(info.intersection.Center().Y + (info.intersection.pointTwo.Y - info.intersection.pointOne.Y) * randomValue);
                    float z1 = (float)GameEntityController.GetPointModel(model).position.Z;
                    float z2 = (float)GameEntityController.GetPointModel(otherModel).position.Z;
                    spawnLocation.z = Mathf.Min(z1, z2) - 0.1f;

                    // Spawn the object
                    GameObject obj = UnityObjectsPool.Instance.FireAndForget(model, prefabName, lifetime);
                    if (obj != null)
                    {
                        spawnLocation         += offset.AsVector3();
                        obj.transform.position = gameToViewCoordinates(spawnLocation);
                        if (localSpace)
                        {
                            obj.transform.SetParent(selfObj.transform);
                        }
                    }
                }
            }
        }
Beispiel #15
0
		// Release event may be accompained by a set animation event and set anchored position.
		// It safely releases at the relative position to parent, taking physics in consideration
		public static void ReleaseAnchoredEntity(GameEntityModel model, int anchorId){
			if (model.anchoredEntities == null || model.anchoredEntities.Count <= anchorId) return;
			GameEntityModel anchoredEntityModel = StateManager.state.GetModel(model.anchoredEntities[anchorId]) as GameEntityModel;
			if (anchoredEntityModel != null){
				anchoredEntityModel.parentEntity = new ModelReference();
				PhysicPointModel pointModel = GameEntityController.GetPointModel(anchoredEntityModel);
				if (pointModel != null){
					pointModel.isActive = true;
					PhysicPointModel parentPointModel = GameEntityController.GetPointModel(model);
					PhysicPointController pointController = pointModel.Controller() as PhysicPointController;
					if (pointController != null && parentPointModel != null){
						// Set position directly
						pointModel.position = parentPointModel.position;
						if (!model.IsFacingRight()) anchoredEntityModel.positionRelativeToParent.X *= -1;
						pointController.SetVelocityAffector(pointModel, PhysicPointController.setPositionffectorName, anchoredEntityModel.positionRelativeToParent);
						anchoredEntityModel.positionRelativeToParent = FixedVector3.Zero;
					}
				}
			}
			model.anchoredEntities[anchorId] = new ModelReference();
		}
        public static bool IsHurtFrontal(GameEntityModel model, bool frontal)
        {
            GameEntityController controller = model.Controller() as GameEntityController;

            if (controller.lastHurts.Count == 0)
            {
                return(false);
            }
            GameEntityModel  hitter      = StateManager.state.GetModel(controller.lastHurts[0].entityId) as GameEntityModel;
            PhysicPointModel modelPoint  = GameEntityController.GetPointModel(model);
            PhysicPointModel hitterPoint = GameEntityController.GetPointModel(hitter);
            bool             isFrontal;

            if (model.IsFacingRight())
            {
                isFrontal = hitterPoint.position.X >= modelPoint.position.X;
            }
            else
            {
                isFrontal = hitterPoint.position.X <= modelPoint.position.X;
            }
            return(isFrontal == frontal);
        }