Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / [2D] How to set a move path

Author
Message
vitinho444
13
Years of Service
User Offline
Joined: 12th Oct 2010
Location:
Posted: 30th Jul 2011 00:42
Hey guys.

Im making my last game in 2D with DarkGDK and i want to make some AI and other things moving.

So i want to know how can i make a path that a certain object (sprite) will follow and stuff..

And how can i import it to use with a bullet controlled by the mouse.

Thanks a lot everyone!

C++ Medium 3.5/5
VB6 Advanced: 4/5
VB.NET Advanced: 4/5
Red Eye
15
Years of Service
User Offline
Joined: 15th Oct 2008
Location:
Posted: 30th Jul 2011 21:11
http://www.policyalmanac.org/games/aStarTutorial.htm

With some refinement you got your own DarkAI.

vitinho444
13
Years of Service
User Offline
Joined: 12th Oct 2010
Location:
Posted: 30th Jul 2011 21:30
Is this 100% compatible with DGDK / C++?

C++ Medium 3.5/5
VB6 Advanced: 4/5
VB.NET Advanced: 4/5
Dar13
16
Years of Service
User Offline
Joined: 12th May 2008
Location: Microsoft VisualStudio 2010 Professional
Posted: 31st Jul 2011 03:48
Quote: "Is this 100% compatible with DGDK / C++?"


Only if you make it to be.

Mireben
15
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 31st Jul 2011 18:30 Edited at: 31st Jul 2011 18:32
If you want a fixed path for a sprite to move along it, you can simply store coordinates in an array and make the sprite move towards the coordinates of the next point. When it has reached the point (by the way "reached a point" is a bit tricky to define for a program, but not so difficult), then move towards the next point, until end of path.

Some simple behaviour is easy to make. Once I made a program in which "entities" represented by triangles moved among obstacles and you could change the behaviour to make entities target a point, follow another entity, move away or hide away from another entity, wander randomly, or patrol an area. It is 3D display but the calculation of waypoints and movement is 2D (entities move only horizontally). If you are interested, here is the downloadable project.

http://forum.thegamecreators.com/?m=forum_view&t=150933&b=22&msg=1844661#m1844661

I admit that it's crude but it's a start... A clever AI is a great challenge. Originally I wanted to implement pathfinding as well in this little test environment, but didn't have the time.
vitinho444
13
Years of Service
User Offline
Joined: 12th Oct 2010
Location:
Posted: 1st Aug 2011 00:34
well, i just need it for a shot (its a fixed path) and for some enemies movement .. something simple because i dont want them to go around like bees and zig zags and that. xD
im keeping following the tutorial that red eye pointed me.

C++ Medium 3.5/5
VB6 Advanced: 4/5
VB.NET Advanced: 4/5
Red Eye
15
Years of Service
User Offline
Joined: 15th Oct 2008
Location:
Posted: 1st Aug 2011 13:33
If it is for a fixed path? Then why not just hard code the coordinates in where the object has to move on to? If it is something like: "pathfinding" so enemies or allies can avoid obstacles go for that link i gave you, but surely you will need some more "rules" later if you want them to shoot (if a particular event happens) and so on, this purely only for pathfinding.

vitinho444
13
Years of Service
User Offline
Joined: 12th Oct 2010
Location:
Posted: 1st Aug 2011 15:50
i never worked with coordinates.. all i know its dbMoveSprite

How can i say to a char move to certain x and Y?

C++ Medium 3.5/5
VB6 Advanced: 4/5
VB.NET Advanced: 4/5
Hawkblood
14
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 2nd Aug 2011 02:38
Math.
You have to determine the angle between where the sprite is and where it is supposed to go. Use dbATANFULL(x,y) to get the angle. The x,y is actually (x1-x2,y1-y2) where x1,y1 is one point and the other point is represented by the x2,y2. Once you have the angle between them, dbRotateSprite(sprite,angle). This will point the sprite in the right direction. If it is pointing 180 out, you have the x1,y1/x2,y2 backwards (just reverse them). Then use dbMoveSprite(sprite,amount). Do a check each frame to determine the distance to target (spot) using d=sqrt((x1-x2)*(x1-x2)+(y1-y1)*(y1-y2)) and if (d<0.5) you are there.

The fastest code is the code never written.
vitinho444
13
Years of Service
User Offline
Joined: 12th Oct 2010
Location:
Posted: 2nd Aug 2011 12:14
wow so simple.

Ok will test it and soon i will answer.

C++ Medium 3.5/5
VB6 Advanced: 4/5
VB.NET Advanced: 4/5
vitinho444
13
Years of Service
User Offline
Joined: 12th Oct 2010
Location:
Posted: 2nd Aug 2011 12:44
I tested it,



It gives a error on the


Error:


C++ Medium 3.5/5
VB6 Advanced: 4/5
VB.NET Advanced: 4/5
Hawkblood
14
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 2nd Aug 2011 17:37
sqrtf(..)

sorry. You want the float version.

The fastest code is the code never written.
vitinho444
13
Years of Service
User Offline
Joined: 12th Oct 2010
Location:
Posted: 2nd Aug 2011 20:03
Dont you have it? xD

C++ Medium 3.5/5
VB6 Advanced: 4/5
VB.NET Advanced: 4/5

Login to post a reply

Server time is: 2024-05-18 13:20:19
Your offset time is: 2024-05-18 13:20:19