Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Fixxxer

Help me in making smooth, natural and direct paths

This topic is 6708 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying to implement some Chase and Destroy game, but i have a big problem in making it look real and smooth, the problem is that the enemy (e) always walks in some geek patterns: the enemy moves diagonaly until it reaches a straight line with the goal, and moves then on that line until it reaches the goal see what i mean !!!!! i want the enemy to chase the goal in some other real and smooth pattren, u can imagine a direct path from the enemy to the goal, which is sort of wavey, like a snake, not continuos line and then another continuos diagonal line ... i would really be greatful for any hints ... please note that i don't care about loosing a couble of blocks, i mean it's not nessecary to pick the ultimate shortest path, although i think that it can be done without this -picking the shortest path but in differant pattarn to follow- Please guys help me !!!!!!!! You maight be wondering about how do i pickup the direction and the path for the enemy ? well, it's that i calculate the distance between the enemy and the goal, from the 8 possiable differant directions that the enemy could follow (x+1,y) and (x+1,y+1) and (x,y+1) and (x-1,y+1) and (x-1,y) and (x-1,y-1) and (x,y-1) and (x+1, y-1), then i pick the one with the shortest distance and i let the enemy move to that direction. ex: if the eastren-north had the minimum distance for the goal then i would move the enemy (x+1,y+1) then i do check again from the new postion, and then i move the enemy, then i check again, and so on... i'm using the Euclidean formula for calculating the distance dist = sqrt( (x2-x1)^2 + (y2-y1)^2 ) and the map is grid based, and there is no weighted stuff at the moment Edited by - fixxxer on 6/26/00 1:18:00 PM

Share this post


Link to post
Share on other sites
Advertisement
If you want smooth curves, Béziercurves are your answer.
You calculate the path to your destination. Put a few control points a few blocks away from the straight path and calculate the Bézier curve between the two ending points. The result should be a smooth curve.

******************************
Stefan Baert

On the day we create intelligence and consciousness, mankind becomes God.
On the day we create intelligence and consciousness, mankind becomes obsolete...
******************************

Share this post


Link to post
Share on other sites
do u know any link or tutorial that deals with making control points and Bezier Curves ???

i''m really new to this, and any help would be greatly helpful,

thnx

Share this post


Link to post
Share on other sites
Not on the net, I''m sorry. I learned Bézier curves in a math course at university.
Did you try a search engine. If there is a tutorial on the net, either Yahoo, Altavista or Google (or another) will have it in their database I''m sure.


******************************
Stefan Baert

On the day we create intelligence and consciousness, mankind becomes God.
On the day we create intelligence and consciousness, mankind becomes obsolete...
******************************

Share this post


Link to post
Share on other sites
quote:
Original post by Fixxxer

the enemy moves diagonaly until it reaches
a straight line with the goal, and moves
then on that line until it reaches the goal

...

well, it''s that i calculate the distance between the enemy and the goal, from the 8 possiable differant directions that the enemy could follow (x+1,y) and (x+1,y+1) and (x,y+1) and (x-1,y+1) and (x-1,y) and (x-1,y-1) and (x,y-1) and (x+1, y-1), then i pick the one with the shortest distance and i let the enemy move to that direction.

...

i''m using the Euclidean formula for calculating the distance dist = sqrt( (x2-x1)^2 + (y2-y1)^2 )
and the map is grid based, and there is no weighted stuff at the moment



Heh, you''re doing a lot of unnecessary work for that very simple effect. What it comes down to is this:


if (enemy.x > my.x)
my.x++;
if (enemy.x < my.x)
my.x--;
if (enemy.y > my.y)
my.y++;
if (enemy.y < my.y)
my.y++;


Not that the above code solves your actual problem, it''s just a much simpler way of achieving the pathfinding you are currently using pythogoras'' theorem etc. for

Share this post


Link to post
Share on other sites
erm.. maybe I''m underestimating the problem, but couldn''t you just:

1. find the angle between the object and it''s destination..
-- x_dist = sin(angle) * radius
-- x_dist / radius = sin(angle)
-- sin^-1(x_dist / radius) = angle
-- angle = sin^-1(x_dist / radius)
2. moves the object one "unit" towards the destination..
-- x = x + sin(angle) * unit
-- y = y + cos(angle) * unit

I''m a little rusty on the math.. but I hope that helps anyways


-qbasicman

Share this post


Link to post
Share on other sites
thank u guys for your posts, i''ll try implementing what u have said, and i''ll tell u what will come up as soon as i finish ...

thnx again

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Check out this page. Lot''s of stuff on bezier curves.

http://www.tinaja.com/cubic01.html


Wayfarer

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!