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.

2D All the way! / Trying to get my "Bots" to follow behind my ship.

Author
Message
MickeyIII
19
Years of Service
User Offline
Joined: 12th Aug 2006
Location: Louisiana
Posted: 20th Jan 2007 20:32
Hey, I need help with some AI. I made a function for Finding the angle between one point and another point. Well, the function works. But when I make my "Bots" move... Well, I really have no clue what they're doing, even when I make some text showing what's going on. I even tried to make a line from the Bot's position to where it's heading and I can't even do that. The Funny part is I can do it all in Visual Basics 6.0 using the same idea someone had done in a tutorial via this link...http://www.gpwiki.org/index.php/VB:Tutorials:Seeking_and_Fleeing

But I can't replicate it into my game. Please download my attachment and help me out. I'll even post a code_snipet if you need.



Thanks,
Mickey III
sixblades
21
Years of Service
User Offline
Joined: 30th Jul 2004
Location:
Posted: 31st Jan 2007 05:00
I don't have nearly enough time to take a good look at all that code, but my guess would be that you aren't getting correct angle values due to the use of the 'atan()' function. Unfortunately, this will not give you the full 360 degrees, for that you will need to call the function 'atanfull()' instead. I'd try working with that, as I made a little program similar to this at some point along the line and ran into this problem.

Cheers!
MickeyIII
19
Years of Service
User Offline
Joined: 12th Aug 2006
Location: Louisiana
Posted: 31st Jan 2007 23:24
Thanks, but that doesn't help much, because that's the first thing I tried. I'll try it again any way though. Thanks.

MickeyIII
MickeyIII
19
Years of Service
User Offline
Joined: 12th Aug 2006
Location: Louisiana
Posted: 18th Feb 2007 02:11


I tried and it didn't work. I even tried to change the find angle function to...



that didn't workd either. I would apriciated if any one has any ideas of what's wrong. If you were to run the downloaded code, you can see that the tiny blue bots just fly around in circles that get larger every time. And you can see the return value of the Find_Angle() function in the upper-left corner...well, sort of. the number does change with every bot in the for next loop, but hopefully someone can help.

Oh...And if it's the way I'm making the bots move and turn, then someone please notify me and give me some tips on how to make it better...

Thanks,

MickeyIII
Van B
Moderator
23
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 18th Feb 2007 21:45
This is how I check the difference between angles:

angdif#=wrapvalue(ang1#-ang2#) : if angdif#>180 then dec angdif#,360

That would set angdif# to the difference, which you can add to the bots angle to make them rotate towards the target.


Good guy, Good guy, Wan...
MickeyIII
19
Years of Service
User Offline
Joined: 12th Aug 2006
Location: Louisiana
Posted: 19th Feb 2007 03:49
Thanks Van B, but that didn't work.

It's most likely the way I adjust my bot's angles using the inc and dec commands...Either I should slow down their speed or their angle increment and decrement...still not sure though. I would still apriciate more help...unless I need a better book than the "DARKBASIC PRO GAME PROGRAMING SECOND EDITION"...That's how I refreshed my memory about the tangent = sine divided by cosine. It's a good book for people like me,but it would be nice to get some more knowledge for Artificial Inteligence. That's why I just make games that don't need any like Breakout or Astroids. Only I like to add more to them to make them more interesting and original.

Help would be greatly apriciated...

Mickey III
Van B
Moderator
23
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 19th Feb 2007 08:51
To limit the rotation, maybe to 5 degrees per loop:

angdif#=wrapvalue(ang1#-ang2#) : if angdif#>180 then dec angdif#,360
if angdif#>5.0 then angdif#=5.0
if angdif#<-5.0 then angdif#=-5.0

I just used this technique for lots of different AI and functions, like having enemies form chains like in snake, having enemies head towards the player when within range, magnetic points that enemies head towards... If I have time later I'll take a look at your full source code, might be able to fix it for you.


Good guy, Good guy, Wan...
MickeyIII
19
Years of Service
User Offline
Joined: 12th Aug 2006
Location: Louisiana
Posted: 19th Feb 2007 16:09
Ok thanks, I'll keep working on another game until I can get some more replies on this. I didn't know this would go this far...

Mickey III
MickeyIII
19
Years of Service
User Offline
Joined: 12th Aug 2006
Location: Louisiana
Posted: 1st Mar 2007 00:06
Hey

I still can't figure this out and I've pretty much completed the Atomic Blox Game...Except for trying to make the high score table(Some ideas would be nice.)

If I could get some more replies, it would be really nice. I plan on making this game an Action\Shooter\RTS game, but for now, I'd like to get this angle thing down. Not to mention a REAL loading Bar and some Splash Screens...

Thanks in Advance,
MickeyIII
MickeyIII
19
Years of Service
User Offline
Joined: 12th Aug 2006
Location: Louisiana
Posted: 1st Mar 2007 00:37
hey

heres that Atomic Blox game that I was talking about W/O the high score table...

MickeyIII
Van B
Moderator
23
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 1st Mar 2007 15:39
With high score tables, I usually make a boolean sort routine, like:

For n=0 to 10
For nn=n to 10

If value(n)>value(nn)
tempvalue=value(n)
value(n)=value(nn)
value(nn)>tempvalue
endif

next nn
next n

That would sort the array 'Value' with 11 indices, so that the lowest value is in indice 10.

After the sort, just compare the player score with the value in indice 10, if it's more, then get the name, and replace the values.

This is quite a psuedo example, but it's pretty much the easiest way to do it. I'd start by making an array, say one for the name, and one for the score, then sort and swap until your lowest value is the last item in the array.

To save your array, well it can get tricky unless you opt for a pure string highscore table array, which would let you SAVE ARRAY the whole lot easily. Like Score$(10,1), where the Y component is 0 for the name, 1 for the score - the score is converted to a string before setting it to the array. Remember you can use boolean on text as well, like...

IF "eggs" > "bacon"

So sorting on a string is nice and easy (and quick).


Good guy, Good guy, Wan...
Thc03
22
Years of Service
User Offline
Joined: 19th May 2004
Location: Pavia - Italy
Posted: 1st Mar 2007 16:23
It's like you're looking at this using the wrong perspective.
You're basicly trying to rotate your bots and make them go forward until the next node, but this heavily depends on theyr traveling speed.
If you try to look at this like you would do finding your way on a cartography, you would notice the path you're going to follow can be traced using lines, smoothed or not.
Now, if you're going to smooth curves, your drawing will be like splines. Otherwise, you should go using straight lines, like in this
.
.

Bye, Berserk.
.
MickeyIII
19
Years of Service
User Offline
Joined: 12th Aug 2006
Location: Louisiana
Posted: 3rd Mar 2007 20:39
Thanks for the high score table tip Van B. I will Impliment it when I understand how to Find the Angle, which by the way, Thc03, I'm not quite sure I follow your explanation and code. And I don't see a return value unless there are Globals involved. Please explain further...

Thanks

MickeyIII
Thc03
22
Years of Service
User Offline
Joined: 19th May 2004
Location: Pavia - Italy
Posted: 4th Mar 2007 11:32
Try putting that code snippet in a blank source file and fill it with

Basicly, it's a method you could also use for drawing path lines (where linear - non smoothed - paths are used) change 10, 10 with your bot x and y, 600, 200 with your bot destination x and y, and make the dot line transforming your bot's coordinates and you're almost done.
Bot orientation can be done with trig functions on difference between start and finish point, so you can use atanfull (I think that is the trig function you need) with xRoad and yRoad values (maybe you'll need to create another xRoad and yRoad wich are not using abs() - but don't remove abs() from the x and y Road variables, as the lines would not draw correctly).
.

Bye, Berserk.
.
Thc03
22
Years of Service
User Offline
Joined: 19th May 2004
Location: Pavia - Italy
Posted: 4th Mar 2007 13:12
Look, try this
instead of the previous one.
Where line turns in circles, those are good points for defining orientation values and aStar path nodes.
Use whatever grid-snapping you like, using up and down cursor keys to define X tile size, and left and right cursors to define Y tile size.
Adding lines will result in a pathway sketch-up, but still implementing this into your code is up to you.
.

Bye, Berserk.
.
MickeyIII
19
Years of Service
User Offline
Joined: 12th Aug 2006
Location: Louisiana
Posted: 4th Mar 2007 18:44
Thc03

I'm not sure that's really what I need for my, game. The atanfull function is really what I'm looking for, and I managed to figure out somewhat of what was wrong with my code. In the followpoint.x
and followpoint.y variables, I forgot to put in the Scroll.x and Scroll.y Values. Now they follow I think, but they keep straying off after a while...I've also added code so that when the bots start getting closer, they slow down until they are too close to move...Here's the updated code in the code snippet...


Thanks

MickeyIII
Thc03
22
Years of Service
User Offline
Joined: 19th May 2004
Location: Pavia - Italy
Posted: 4th Mar 2007 22:04
I don't mind on reading all that code.
Could you substitute models with dummy object for demonstration purposes?
However, the idea behind my code was, drawing a line set, to define a path to make the bot follow it.
Substancially, every time you "snap" with the grid, a new path finding node is created, while the bots will have to follow that path.
However, since you got the problem, glad to know.
.

Bye, Berserk.
.

Login to post a reply

Server time is: 2026-07-04 20:45:07
Your offset time is: 2026-07-04 20:45:07