Beispiel #1
0
        public void SetContact()
        {
            float length = 8.0f;             //Engine.Singleton.GameCamera.DistanceNow + 1.0f;

            Vector3 AimPosition = new Vector3();

            AimPosition.x = (float)System.Math.Sin((double)-getY().ValueRadians) * length;
            AimPosition.x = (float)System.Math.Cos((double)getX().ValueRadians) * AimPosition.x + Engine.Singleton.Camera.Position.x;
            AimPosition.y = (float)System.Math.Sin((double)getX().ValueRadians) * length + Engine.Singleton.Camera.Position.y;
            AimPosition.z = (float)System.Math.Cos((double)getY().ValueRadians) * -length;
            AimPosition.z = (float)System.Math.Cos((double)getX().ValueRadians) * AimPosition.z + Engine.Singleton.Camera.Position.z;

            Contact = null;

            PredicateRaycast raycast = new PredicateRaycast((b => !(b.UserData is TriggerVolume) && (b.MaterialGroupID != Engine.Singleton.MaterialManager.CharacterSensorMaterialID) && (b.MaterialGroupID != Engine.Singleton.MaterialManager.LevelMaterialID)));

            raycast.Go(Engine.Singleton.NewtonWorld, Engine.Singleton.Camera.Position, AimPosition);

            if (raycast.Contacts.Count != 0)
            {
                raycast.SortContacts();
                AimPosition = Position
                              + (AimPosition - Position) * raycast.Contacts[0].Distance
                              + raycast.Contacts[0].Normal * 0.01f * length;

                if (raycast.Contacts[0].Body.UserData is GameObject)
                {
                    Contact = raycast.Contacts[0].Body.UserData as GameObject;
                }
            }
        }
Beispiel #2
0
        public void Update()
        {
            if (!Engine.Singleton.HumanController.HUDMenu.IsVisible)
            {
                Vector3 offset =
                Character.Node.Orientation * (-Vector3.UNIT_Z +
                  (Vector3.UNIT_Y * (float)System.Math.Tan(Angle.ValueRadians))
                  ).NormalisedCopy * Distance;

                Vector3 head = Character.Node.Position + Character.Profile.HeadOffset;
                Vector3 desiredPosition = head + offset;

                InterPosition += (desiredPosition - InterPosition) * 0.1f;

                PredicateRaycast raycast = new PredicateRaycast((b => !(b.UserData is TriggerVolume)));
                raycast.Go(Engine.Singleton.NewtonWorld, head, InterPosition);
                if (raycast.Contacts.Count != 0)
                {
                    raycast.SortContacts();
                    Engine.Singleton.Camera.Position = head
                      + (InterPosition - head) * raycast.Contacts[0].Distance
                      + raycast.Contacts[0].Normal * 0.15f;

                    DistanceNow = raycast.Contacts[0].Distance;
                }
                else
                {
                    Engine.Singleton.Camera.Position = InterPosition;
                    DistanceNow = Distance;
                }

                Engine.Singleton.Camera.LookAt(head);
            }
            else
            {
                Engine.Singleton.Camera.Position = new Vector3(3.5f, 1.5f, 2.25f);
                Engine.Singleton.Camera.LookAt(new Vector3(0, 0, 0));
            }
        }
Beispiel #3
0
        public void Update()
        {
            if (!Engine.Singleton.HumanController.HUDMenu.IsVisible)
            {
                Vector3 offset =
                    Character.Node.Orientation * (-Vector3.UnitZ +
                                                  (Vector3.UnitY * (float)System.Math.Tan(Angle.ValueRadians))
                                                  ).NormalisedCopy * Distance;

                Vector3 head            = Character.Node.Position + Character.Profile.HeadOffset;
                Vector3 desiredPosition = head + offset;

                InterPosition += (desiredPosition - InterPosition) * 0.1f;

                PredicateRaycast raycast = new PredicateRaycast((b => !(b.UserData is TriggerVolume)));
                raycast.Go(Engine.Singleton.NewtonWorld, head, InterPosition);
                if (raycast.Contacts.Count != 0)
                {
                    raycast.SortContacts();
                    Engine.Singleton.Camera.Position = head
                                                       + (InterPosition - head) * raycast.Contacts[0].Distance
                                                       + raycast.Contacts[0].Normal * 0.15f;

                    DistanceNow = raycast.Contacts[0].Distance;
                }
                else
                {
                    Engine.Singleton.Camera.Position = InterPosition;
                    DistanceNow = Distance;
                }

                Engine.Singleton.Camera.LookAt(head);
            }
            else
            {
                Engine.Singleton.Camera.Position = new Vector3(3.5f, 1.5f, 2.25f);
                Engine.Singleton.Camera.LookAt(new Vector3(0, 0, 0));
            }
        }
Beispiel #4
0
        public override void Update()
        {
            walkAnim = Entity.GetAnimationState("WALK");
            idleAnim = Entity.GetAnimationState("IDLE");
            attackAnim = Entity.GetAnimationState("ATTACK");
            deadAnim = Entity.GetAnimationState("DEAD");
            Tree.e_Visit(this);

            if (Statistics.aktualnaZywotnosc <= 0)
                State = StateTypes.DEAD;

            double Distance = Engine.Distance(Position, Engine.Singleton.HumanController.Character.Position);
            Distance = System.Math.Abs(Distance);

            if (Distance <= _ZasiegWzroku && State != StateTypes.DEAD)
            {
                PredicateRaycast raycast = new PredicateRaycast((b => !(b.UserData is TriggerVolume)));
                raycast.Go(Engine.Singleton.NewtonWorld, Position + Profile.HeadOffset, Engine.Singleton.HumanController.Character.Position);

                if (raycast.Contacts.Count <= 1)
                {
                    isSeen = true;

                    TurnTo(Engine.Singleton.HumanController.Character.Position);
                }

                else
                    isSeen = false;
            }

            if (Distance <= _ZasiegOgolny)
            {
                isReachable = true;
            }

            else
                isReachable = false;

            if ((isReachable == true) && Distance > Profile.DystansKontaktu && State != StateTypes.DEAD && FriendlyType == Character.FriendType.ENEMY)
            {
                Engine.Singleton.CurrentLevel.navMesh.AStar(Position, Engine.Singleton.HumanController.Character.Position);
                if (Engine.Singleton.CurrentLevel.navMesh.TriPath.Count > 1)
                {
                    Engine.Singleton.CurrentLevel.navMesh.GetPortals();
                    WalkPath = Engine.Singleton.CurrentLevel.navMesh.Funnel();

                    idleAnim.Enabled = false;
                    walkAnim.Enabled = true;
                    attackAnim.Enabled = false;
                    walkAnim.Loop = true;
                    walkAnim.AddTime(1.0f / 90.0f);

                    FollowPathOrder = true;
                    //MoveOrder = true;
                    State = StateTypes.WALK;
                }
            }

            else
            {
                FollowPathOrder = false;

                if (State == StateTypes.WALK)
                    State = StateTypes.IDLE;

                switch (State)
                {
                    case StateTypes.IDLE:
                        walkAnim.Enabled = false;
                        idleAnim.Enabled = true;
                        attackAnim.Enabled = false;
                        idleAnim.Loop = true;
                        idleAnim.AddTime(1.0f / 90.0f);
                        break;
                    case StateTypes.DEAD:
                        walkAnim.Enabled = false;
                        idleAnim.Enabled = false;
                        attackAnim.Enabled = false;
                        deadAnim.Enabled = true;
                        deadAnim.AddTime(1.0f / 90.0f);
                        deadAnim.Loop = false;
                        //Animacja deda.

                        if (deadAnim.HasEnded && !recalculatedAfterDead)
                        {
                            //recalculatedAfterDead = true;
                            //RecalculateCollision();           //<- FIX THAT SHIET!
                        }

                        break;
                    //Animacja ataku bedzie tam nizej w case StateTypes.Attack, nie tutaj!!

                }
                if (isReachable)
                {
                    switch (State)
                    {
                        case StateTypes.IDLE:
                            //Console.WriteLine(FriendlyType.ToString());
                            if (FriendlyType == Character.FriendType.ENEMY)
                            {
                                State = StateTypes.ATTACK;
                            }
                            break;

                        case StateTypes.ATTACK:
                            walkAnim.Enabled = false;
                            idleAnim.Enabled = false;
                            attackAnim.Enabled = true;
                            attackAnim.Loop = false;
                            attackAnim.AddTime(1.0f / 90.0f);

                            if (Engine.Singleton.HumanController.Character.Statistics.aktualnaZywotnosc > 0 && attackAnim.HasEnded)
                            {
                                attackAnim.TimePosition = 0;
                                Attack();
                                //Engine.Singleton.HumanController.Character.Statistics.aktualnaZywotnosc -= Statistics.Sila;
                            }
                            break;

                        case StateTypes.DEAD:
                            IsContainer = true;
                            break;
                    }
                }
            }
        }
Beispiel #5
0
        public override void Update()
        {
            walkAnim   = Entity.GetAnimationState("WALK");
            idleAnim   = Entity.GetAnimationState("IDLE");
            attackAnim = Entity.GetAnimationState("ATTACK");
            deadAnim   = Entity.GetAnimationState("DEAD");
            Tree.e_Visit(this);

            if (Statistics.aktualnaZywotnosc <= 0)
            {
                State = StateTypes.DEAD;
            }

            double Distance = Engine.Distance(Position, Engine.Singleton.HumanController.Character.Position);

            Distance = System.Math.Abs(Distance);

            if (Distance <= _ZasiegWzroku && State != StateTypes.DEAD)
            {
                PredicateRaycast raycast = new PredicateRaycast((b => !(b.UserData is TriggerVolume)));
                raycast.Go(Engine.Singleton.NewtonWorld, Position + Profile.HeadOffset, Engine.Singleton.HumanController.Character.Position);

                if (raycast.Contacts.Count <= 1)
                {
                    isSeen = true;

                    TurnTo(Engine.Singleton.HumanController.Character.Position);
                }

                else
                {
                    isSeen = false;
                }
            }

            if (Distance <= _ZasiegOgolny)
            {
                isReachable = true;
            }

            else
            {
                isReachable = false;
            }

            if ((isReachable == true) && Distance > Profile.DystansKontaktu && State != StateTypes.DEAD && FriendlyType == Character.FriendType.ENEMY)
            {
                Engine.Singleton.CurrentLevel.navMesh.AStar(Position, Engine.Singleton.HumanController.Character.Position);
                if (Engine.Singleton.CurrentLevel.navMesh.TriPath.Count > 1)
                {
                    Engine.Singleton.CurrentLevel.navMesh.GetPortals();
                    WalkPath = Engine.Singleton.CurrentLevel.navMesh.Funnel();

                    idleAnim.Enabled   = false;
                    walkAnim.Enabled   = true;
                    attackAnim.Enabled = false;
                    walkAnim.Loop      = true;
                    walkAnim.AddTime(1.0f / 90.0f);

                    FollowPathOrder = true;
                    //MoveOrder = true;
                    State = StateTypes.WALK;
                }
            }

            else
            {
                FollowPathOrder = false;

                if (State == StateTypes.WALK)
                {
                    State = StateTypes.IDLE;
                }

                switch (State)
                {
                case StateTypes.IDLE:
                    walkAnim.Enabled   = false;
                    idleAnim.Enabled   = true;
                    attackAnim.Enabled = false;
                    idleAnim.Loop      = true;
                    idleAnim.AddTime(1.0f / 90.0f);
                    break;

                case StateTypes.DEAD:
                    walkAnim.Enabled   = false;
                    idleAnim.Enabled   = false;
                    attackAnim.Enabled = false;
                    deadAnim.Enabled   = true;
                    deadAnim.AddTime(1.0f / 90.0f);
                    deadAnim.Loop = false;
                    //Animacja deda.

                    if (deadAnim.HasEnded && !recalculatedAfterDead)
                    {
                        //recalculatedAfterDead = true;
                        //RecalculateCollision();           //<- FIX THAT SHIET!
                    }

                    break;
                    //Animacja ataku bedzie tam nizej w case StateTypes.Attack, nie tutaj!!
                }
                if (isReachable)
                {
                    switch (State)
                    {
                    case StateTypes.IDLE:
                        //Console.WriteLine(FriendlyType.ToString());
                        if (FriendlyType == Character.FriendType.ENEMY)
                        {
                            State = StateTypes.ATTACK;
                        }
                        break;

                    case StateTypes.ATTACK:
                        walkAnim.Enabled   = false;
                        idleAnim.Enabled   = false;
                        attackAnim.Enabled = true;
                        attackAnim.Loop    = false;
                        attackAnim.AddTime(1.0f / 90.0f);

                        if (Engine.Singleton.HumanController.Character.Statistics.aktualnaZywotnosc > 0 && attackAnim.HasEnded)
                        {
                            attackAnim.TimePosition = 0;
                            Attack();
                            //Engine.Singleton.HumanController.Character.Statistics.aktualnaZywotnosc -= Statistics.Sila;
                        }
                        break;

                    case StateTypes.DEAD:
                        IsContainer = true;
                        break;
                    }
                }
            }
        }