• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
MohammadAhmed

chasing

9 posts in this topic

Hello , here is an image show what I am gonna to do in my XNA game , I want to check if the player is inside zone range and if yes then attack the player , I tried to do this using checking ray but it's odd and give null results as player must be in front of enemy so he can be detected !

jvcsdkjqg3jd9dj6g.jpg

0

Share this post


Link to post
Share on other sites

Since you didn't specify, I'm assuming 2D for this. I'm also guessing each enemy has their "zone" or view distance stored with the rest of their information. You can find the distance between the player and the enemy by using the following

float x = player.x - enemy.x; // Distance between x positions of player and enemy
float y = player.y - enemy.y; // Likewise, difference between y values of positions
 
float distance = Math.sqrt((x * x) - (y * y)); // Replace with your math library - this is a Java implementation

 

Then, if the distance calculated is less than than the enemy's view distance or zone, the enemy attacks. For making sure the enemy actually 'sees' the player, you can do a check where, if the enemy is facing left and the player's x position is left of (less than) the enemy's, attack. If the player's x position is right of (greater than) the enemy's, attack. You can adjust this to have the enemy have a view angle as well so he can't see floor to ceiling but has a more realistic feeling field of view.

1

Share this post


Link to post
Share on other sites

thanks David smile.png , sorry I am assuming 3d of course smile.png  , I have bounding box surrounding my player and also for the enemy , now I can fire a ray to check collision in front of enemy then if I am collide with the ray enemy can attack else enemy can't , but this looks odd and very bad as I must be in front of enemy , so instead I want a zone ( circle ) which is dangerous circle so that when I am inside this circle enemy can attack 

Note : anyone have another strategy pls share with some code if you can smile.png .

David , you said that I can do this by using view angle for each enemy instead , can you post some code if you can taking in mind the ray I can use for each model in the game .
dhk5taecpo6k6mp6g.jpg

Edited by mrmohadnan
0

Share this post


Link to post
Share on other sites

It doesn't matter if it is 2d or 3d, you could use the same math

 

 

float enemyConeAngle = 0.6f;
float enemyZoneRadius = 10.0f;

vec3 enemyPos = enemy.pos;
vec3 enemyDir = normalize(enemy.LookAt - enemyPos);
vec3 playerPos = player.pos;
vec3 toPlayerDir = normalize(playerPos - enemyPos);
 
float angle = acos(dot(enemyDir, toPlayerDir));
float distance = sqrt(dot(playerPos - enemyPos));

if(angle < enemyConeAngle && distance < enemyZoneRadius)
{
    enemy.state = chase_player;
}
 
...
if(enemy.state == chase_player)
{
    float moveSpeed = 3.0f;
    enemy.pos += toPlayerDir * moveSpeed * deltaTime; // move towards player
}

 

On top of my head, might made mistake somewhere.

Edited by belfegor
1

Share this post


Link to post
Share on other sites

Oh again brother belfegor thaaaaaaaaaanks  , I tried this code but the enemy move at his place ( no translation is done ! )not move , what  do think belfegor ? 

 

 double distanceX = (double)(cci.CharacterController.Body.Position.X - dwarfChrachterController.Body.Position.X);
            double distanceZ = (double)(cci.CharacterController.Body.Position.Z - dwarfChrachterController.Body.Position.Z);
            if (Math.Sqrt( (distanceX * distanceX) + (distanceZ * distanceZ)) <=500)
            {
                RunController(dwarfAnimatior, dwarfwalk);

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

                Vector3.Normalize(direction);

                dwarfChrachterController.Body.Position += direction * 5 * gameTime.ElapsedGameTime.Seconds;

                if (enemyRay.Intersects(cci.CharacterController.Body.CollisionInformation.BoundingBox) <= 50)
                {
                    sound.playAh();
                }
            }
Edited by mrmohadnan
0

Share this post


Link to post
Share on other sites

You should learn to debug your code a little.For example put some breakpoints to see what is going on. You could put one in body of if(Math.Sqrt(...)) statement to see if code that is inside is executed.

 

In my engine 500 would be half of kilometer.

Edited by belfegor
1

Share this post


Link to post
Share on other sites

belfegor , even when I am in the range he move at his position not translated toward me ? ok I will brothers thanks again :)

0

Share this post


Link to post
Share on other sites

yeah , thaaaanks belfegor , I got it working and now it's moving toward me , now just orient the enemy when he move toward me so that his body.front direction facing me ! can you refine your code a little bit as you do with steering ? 

usry54ec1lm8a1y6g.jpg

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 velocity =(cci.CharacterController.Body.Position- dwarfChrachterController.Body.Position) ;

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

                dwarfChrachterController.HorizontalMotionConstraint.MovementDirection += new Vector2(velocity.X,velocity.Z);

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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0