• 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
Haegr

Moving away from or towards the player

14 posts in this topic

I'd like to implement some simple AI, which would have the enemies moving away from my player, or towards him if they are a larger enemy.

I was looking for suggestions on how people might go about this, I currently plan on sampling the distance and dot product between the enemy and the player and updating the enemies velocity accordingly, my problem lies in how to adjust the angle - I had planned on reversing the dot product to some extent, entering an angle and the players position which would give me the desired enemy position.

I am just wondering if these would be a half decent way to implement such a thing, or if any one had any better ideas. I should mention that this is in 3D but ignoring the Y axis, so it's really just a 2D test.

Thanks.
0

Share this post


Link to post
Share on other sites
The dot-product is a tool that uses 2 difference vectors (not position vectors). Which difference vectors do you want to use?

Do you need an explicit angle at all? You can compute the difference vector from the current enemy position to the current (or predicted) player position. With it you have both the total distance and (after normalization) the direction of movement (assuming that pathfinding didn't play a role here).

If not yet known: Usually one is directed to look at [url="http://www.red3d.com/cwr/steer/"]Steering Behaviors[/url] and its open source counterpart [url="http://opensteer.sourceforge.net/"]OpenSteer[/url] for such kinds of things.
0

Share this post


Link to post
Share on other sites
[quote name='haegarr' timestamp='1301990921' post='4794537']
The dot-product is a tool that uses 2 difference vectors (not position vectors). Which difference vectors do you want to use?

Do you need an explicit angle at all? You can compute the difference vector from the current enemy position to the current (or predicted) player position. With it you have both the total distance and (after normalization) the direction of movement (assuming that pathfinding didn't play a role here).

If not yet known: Usually one is directed to look at [url="http://www.red3d.com/cwr/steer/"]Steering Behaviors[/url] and its open source counterpart [url="http://opensteer.sourceforge.net/"]OpenSteer[/url] for such kinds of things.
[/quote]

Why would one go about using OpenSteer? That's just steering one away from actually learning how to do the real work.

Also, that is hard to do....Very hard.
0

Share this post


Link to post
Share on other sites
[quote name='BB1995' timestamp='1301992056' post='4794547']
Why would one go about using OpenSteer? That's just steering one away from actually learning how to do the real work.

Also, that is hard to do....Very hard.
[/quote]
The OP asked for "on how people might go about this", and OpenSteer demonstrates such a thing. The OP is free to pick the theory only, look at the implementation, find references to other solutions, or else decide to directly use OpenSteer; I haven't made any suggestion to actually [i]use[/i] OpenSteer but just directed him to a place where some research can be done.
0

Share this post


Link to post
Share on other sites
[quote name='haegarr' timestamp='1301997625' post='4794567']
[quote name='BB1995' timestamp='1301992056' post='4794547']
Why would one go about using OpenSteer? That's just steering one away from actually learning how to do the real work.

Also, that is hard to do....Very hard.
[/quote]
The OP asked for "on how people might go about this", and OpenSteer demonstrates such a thing. The OP is free to pick the theory only, look at the implementation, find references to other solutions, or else decide to directly use OpenSteer; I haven't made any suggestion to actually [i]use[/i] OpenSteer but just directed him to a place where some research can be done.
[/quote]

Hey, don't argue with her, she's too hot
1

Share this post


Link to post
Share on other sites
I am looking more to learn from this so I would prefer to do this myself and understand how it is done.

How would I go about using the two positions and normalization to get the direction? While I understand how to find the distance it is the direction I am having trouble with.
0

Share this post


Link to post
Share on other sites
Ok, so you have a player at P (px,pz) and an enemy at E (ex,ez). Make a vector V (vx,vz) from the enemy to the player: vx=px-ex, vz=pz-ez.
Normalize V: length=sqrt(vx*vx+vz*vz), vx=vx/length, vz=vz/length. V now has a length of 1 and points from the enemy to the player.
To make the enemy move towards the player, multiply V by the enemy's speed and add V to the enemy position E: ex=ex+speed*vx, ez=ez+speed*vz.
To make the enemy move away from the player, multiply V by the enemy's speed and subtract V from the enemy position E: ex=ex-speed*vx, ez=ez-speed*vz.
You can find the direction from V but you don't really need to.
1

Share this post


Link to post
Share on other sites
Thank you very much Simon, I can see how that works.

I would still like to understand the process of using normalization, I am not quite sure how it would return the direction because I was under the impressing there were 2 normals, not 1.
0

Share this post


Link to post
Share on other sites
[quote name='Haegr' timestamp='1302010754' post='4794619']
Thank you very much Simon, I can see how that works.

I would still like to understand the process of using normalization, I am not quite sure how it would return the direction because I was under the impressing there were 2 normals, not 1.
[/quote]
Don't confuse 'normals' (vectors at right angles to things) with 'normalizing' (making a vector have a length of 1).
Vectors implicitly have a direction: the vector (1,0) has a length of 1 and points along the x axis, (1,1) has length sqrt(2) and points 45' up from the x axis, (-1,0) has length 1 and points down the x axis, &c.
1

Share this post


Link to post
Share on other sites
[quote name='Haegr' timestamp='1302010754' post='4794619']
I would still like to understand the process of using normalization, I am not quite sure how it would return the direction because I was under the impressing there were 2 normals, not 1.
[/quote]
The term "normalization" in the context of vectors means that the vector is divided by its length, yielding in a vector of the same direction but with unit length (i.e. its length is 1). Although any vector (with length > 0) can be used for a specific direction, the unit vector is usually favored. The difference vector between 2 points encodes both the distance of the 2 points and the direction from the one to the other point.

The therm "normal" in the context of vectors means usually that the vector is perpendicular to something, e.g. to another vector or to a surface or whatever.
1

Share this post


Link to post
Share on other sites
Thank you both very much for explaining that!

So to move away from the player I would calculate the distance between the two, normalize this and then reverse it to give me the opposite direction?
0

Share this post


Link to post
Share on other sites
[quote name='Haegr' timestamp='1302017239' post='4794659']
Thank you both very much for explaining that!

So to move away from the player I would calculate the distance between the two, normalize this and then reverse it to give me the opposite direction?
[/quote]
Pretty much, but it's 'calculate the [b]vector[/b] between the two, normalize this (using the distance) and then reverse it to get the opposite direction'.
1

Share this post


Link to post
Share on other sites
Thank you both very much for the help, I'll get this implemented now.
0

Share this post


Link to post
Share on other sites
Just looking for a bit more added advice here.

I'm adding behavior for the AI to detect if it is too close to another ai, and move accordingly. My problem is that if I happen to get two opposite movement vectors, after I add them the result will be 0. How should one respond in this situation? (for my simulation the ai will simply explode, but I mean this as a broader question, if I were doing simulation for example)
0

Share this post


Link to post
Share on other sites
No easy answers there! Try looking at the [url="http://www.red3d.com/cwr/steer/"]red3D[/url] steering examples for some ideas.
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