🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Help me in making smooth, natural and direct paths

Started by
7 comments, last by Fixxxer 24 years ago
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
"If you don''t like something, change it. If you can''t change it, change the way you think about it!""He who asks is a fool for five minutes, but he who does not ask remains a fool forever.""Imagination is more important than knowledge, for knowledge is limited while imagination embraces the entire world."(Einstein)"The normal teacher tells. The good teacher explains. The superior teacher demonstrates. The great teacher inspires."(William Arthur Ward)
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...
******************************
******************************StrategicAllianceOn the day we create intelligence and consciousness, mankind becomes God.On the day we create intelligence and consciousness, mankind becomes obsolete...******************************
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
"If you don''t like something, change it. If you can''t change it, change the way you think about it!""He who asks is a fool for five minutes, but he who does not ask remains a fool forever.""Imagination is more important than knowledge, for knowledge is limited while imagination embraces the entire world."(Einstein)"The normal teacher tells. The good teacher explains. The superior teacher demonstrates. The great teacher inspires."(William Arthur Ward)
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...
******************************
******************************StrategicAllianceOn the day we create intelligence and consciousness, mankind becomes God.On the day we create intelligence and consciousness, mankind becomes obsolete...******************************
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
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
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
"If you don''t like something, change it. If you can''t change it, change the way you think about it!""He who asks is a fool for five minutes, but he who does not ask remains a fool forever.""Imagination is more important than knowledge, for knowledge is limited while imagination embraces the entire world."(Einstein)"The normal teacher tells. The good teacher explains. The superior teacher demonstrates. The great teacher inspires."(William Arthur Ward)
Check out this page. Lot''s of stuff on bezier curves.

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


Wayfarer
Check out this page. Lot''s of stuff on bezier curves.

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


Wayfarer

This topic is closed to new replies.

Advertisement