Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


#Actualmrmohadnan

Posted 21 May 2013 - 04:27 PM

...........................


#2mrmohadnan

Posted 21 May 2013 - 03:38 PM

Yeah , belfegor , sorry but the code you post did not fulfill what I need , I need view field for each enemy then if he detec me then attack ( chasing ) 

2 : The enemy dos not move toward me ,  I had used your code and play with it , the enemy detec me 100% but the enemy stays at original position ??


 

Ray enmyRay;
            enmyRay.Position = enemyDwarfChrachterController.Body.Position;
            enmyRay.Direction = Vector3.Normalize(enemyDwarfChrachterController.Body.OrientationMatrix.Forward);
            double distanceX = (double)(cci.CharacterController.Body.Position.X - enemyDwarfChrachterController.Body.Position.X);
            double distanceZ = (double)(cci.CharacterController.Body.Position.Z - enemyDwarfChrachterController.Body.Position.Z);

            Vector3 direction = player.CharacterController.Body.Position - enemyDwarfChrachterController.Body.Position;

            if (Math.Sqrt( (distanceX * distanceX) + (distanceZ * distanceZ)) <=500)
            {
                RunController(dwarfAnimatior, dwarfwalk);
                
                Vector3.Normalize(direction);

                enemyDwarfChrachterController.HorizontalMotionConstraint.MovementDirection += new Vector2(direction.X,direction.Z) 
                    * 5 * gameTime.ElapsedGameTime.Seconds;

                if (enmyRay.Intersects(player.CharacterController.Body.CollisionInformation.BoundingBox) <= 50)
                {
                    RunController(dwarfAnimatior, dwarfattak);
                    sound.playAh();
                }
                direction = player.CharacterController.Body.Position - enemyDwarfChrachterController.Body.Position;
            }

#1mrmohadnan

Posted 21 May 2013 - 03:37 PM

Yeah , belfegor , sorry but the code you post did not fulfill what I need , I need view field for each enemy then if he detec me then attack ( chasing ) 

2 : The enemy dos not move toward me ,  I had used your code and play with it , the enemy detec me 100% but the enemy stays at original position ??


 

Ray enmyRay;
            enmyRay.Position = dwarfChrachterController.Body.Position;
            enmyRay.Direction = Vector3.Normalize(dwarfChrachterController.Body.OrientationMatrix.Forward);
            double distanceX = (double)(cci.CharacterController.Body.Position.X - dwarfChrachterController.Body.Position.X);
            double distanceZ = (double)(cci.CharacterController.Body.Position.Z - dwarfChrachterController.Body.Position.Z);

            Vector3 direction = cci.CharacterController.Body.Position - dwarfChrachterController.Body.Position;

            if (Math.Sqrt( (distanceX * distanceX) + (distanceZ * distanceZ)) <=500)
            {
                RunController(dwarfAnimatior, dwarfwalk);
                
                Vector3.Normalize(direction);

                dwarfChrachterController.HorizontalMotionConstraint.MovementDirection += new Vector2(direction.X,direction.Z) 
                    * 5 * gameTime.ElapsedGameTime.Seconds;

                if (enmyRay.Intersects(cci.CharacterController.Body.CollisionInformation.BoundingBox) <= 50)
                {
                    RunController(dwarfAnimatior, dwarfattak);
                    sound.playAh();
                }
                direction = cci.CharacterController.Body.Position - dwarfChrachterController.Body.Position;
            }

PARTNERS