Example #1
0
        /// <summary>
        /// Event as soon as a contact is created for a collision.
        /// This event contains more information about the collision.
        /// </summary>
        /// <param name="obj"></param>
        private void Events_ContactCreated(Contact obj)
        {
            if (!IsActive || !GameManager.GameActive)
            {
                return;
            }

            Collider body1 = obj.Body1 as Collider;
            Collider body2 = obj.Body2 as Collider;

            bool body1IsPlayer = body1?.GameObject?.tag == ObjectTag.Player;
            bool body2IsPlayer = body2?.GameObject?.tag == ObjectTag.Player;

            bool body1IsGround = body1?.GameObject?.tag == ObjectTag.Ground;
            bool body2IsGround = body2?.GameObject?.tag == ObjectTag.Ground;

            bool body1IsPureCollider = body1?.PureCollider == true;
            bool body2IsPureCollider = body2?.PureCollider == true;

            bool body1IsStatic = body1?.IsStatic == true;
            bool body2IsStatic = body2?.IsStatic == true;

            if (body1IsPlayer && !body2IsPureCollider && body2IsStatic && !body2IsGround)
            {
                SteerableCollider sc = body1 as SteerableCollider;
                HandlePlayerCollision(sc, body2, obj.Position2, -1 * obj.Normal);
            }
            else if (body2IsPlayer && !body1IsPureCollider && body1IsStatic && !body1IsGround)
            {
                SteerableCollider sc = body2 as SteerableCollider;
                HandlePlayerCollision(sc, body1, obj.Position1, obj.Normal);
            }
        }
Example #2
0
        /// <summary>
        /// Initialization of the rigid-body
        /// </summary>
        public override void Awake()
        {
            CalculateShape(ShapeType.Box);

            RigidBody = new SteerableCollider(CollisionShape)
            {
                Position      = Conversion.ToJitterVector(transform.position),
                Orientation   = JMatrix.CreateFromQuaternion(Conversion.ToJitterQuaternion(transform.rotation)),
                CenterOfMass  = CenterOfMass,
                IsStatic      = IsStatic,
                IsActive      = IsActive,
                Tag           = BodyTag.DrawMe,
                Mass          = 20.0f,
                GameObject    = gameObject,
                SyncedObjects = SyncedObjects,
                Material      = new Jitter.Dynamics.Material {
                    KineticFriction = 1.0f, Restitution = 1.0f, StaticFriction = 1.0f
                }
            };

            StartOrientation = RigidBody.Orientation;
            StartPosition    = RigidBody.Position;

            PhysicsManager.Instance.World.AddBody(RigidBody);
        }
Example #3
0
        public override void Start()
        {
            base.Start();

            _other = ElementManager.Instance.Enemy(TeamIndex);

            CamController = GameObject.FindGameObjectWithName("camera_" + PlayerIndex).GetComponent <CameraController>();
            //CamController.Start(); // why is start called on this?

            //subcomponents (shorten)
            pA = gameObject.GetComponent <PlayerAttack>();
            pM = gameObject.GetComponent <PlayerMovement>();
            pI = gameObject.GetComponent <PlayerInventory>();
            pP = gameObject.GetComponent <PlayerPowerup>();
            pS = gameObject.GetComponent <PlayerStamina>();

            MovingRigidBody mrb = gameObject.GetComponent <MovingRigidBody>();

            _steerableCollider = mrb.SteerableCollider;

            // Reset start position
            transform.position = startPosition;
            transform.rotation = Quaternion.Identity;

            if (_steerableCollider != null)
            {
                _steerableCollider.Speed       = JVector.Zero;
                _steerableCollider.RotationY   = 0;
                _steerableCollider.Position    = Conversion.ToJitterVector(startPosition);
                _steerableCollider.Orientation = JMatrix.CreateRotationY(0);
            }
        }
Example #4
0
        // --------------------- BASE METHODS ------------------
        public override void Start()
        {
            playerInventory = gameObject.GetComponent <PlayerInventory>();

            MovingRigidBody dynamicRigidBody = gameObject.GetComponent <MovingRigidBody>();

            _collider = dynamicRigidBody?.RigidBody as SteerableCollider;

            // Reset all variables to the start-values
            Reset();
        }
Example #5
0
        private void HandlePlayerCollision(SteerableCollider player, Collider other, JVector collisionPoint, JVector normal)
        {
            //float angle = JVector.Dot(right, normal) > 0.0f ? -15.0f : 15.0f;
            float angle = 0.0f;

            angle += MathHelper.ToDegrees(player.RotationY);

            JVector forward = Conversion.ToJitterVector(player.GameObject.transform.Forward);

            // If the player is driving away of the wall there should be no collision-handling
            if (JVector.Dot(forward, normal) > 0.0f)
            {
                return;
            }

            JVector newPosition = ProjectToNonCollision(player, collisionPoint, normal);

            player.GameObject.GetComponent <Player>().SetCollisionState(other, Conversion.ToXnaVector(newPosition), angle);
            player.Position = newPosition;
        }