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 Physics & Dark A.I. & Dark Dynamix / [A.I.] Wandering around a dynamicly sized circle?

Author
Message
Sunflash
19
Years of Service
User Offline
Joined: 28th Jun 2005
Location: Seattle, Wa
Posted: 24th Jun 2008 12:12
Hey guys,

I'm desperate, I can't seem to get my 2D characters to wander around a dynamically growing circular area. As the game continues, the area the characters are to defend grows, but when I set my characters to defend the circular area, they just go straight to the origin of the circle. How can I get them to wander, or search the circle?

Thanks,
-Sunflash

Mountain Dew, happyness in a bottle.
HowDo
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: United Kingdom
Posted: 24th Jun 2008 12:58
at a guess cos sin.

Dark Physics makes any hot drink go cold.
Sunflash
19
Years of Service
User Offline
Joined: 28th Jun 2005
Location: Seattle, Wa
Posted: 25th Jun 2008 03:47 Edited at: 25th Jun 2008 04:52
Ok, so I placed this code in my main loop:



But whenever the character starts moving to a random position, it instantly stops and moves back to the Idle Position. Grrr, I have no clue as to what could be counteracting the random movement command, I've never had this problem before either. Anyone care to venture a guess as to what is going on?

This is the code executed when the entity is created:



Thanks,
-Sunflash


EDIT:
@HowDo, thanks mate, thats how I ended up doing it

I still haven't figured out whats going on with the Random Movement function, but the way I ended up coding it works much better, here is the code if anyone is wondering:



Mountain Dew, happyness in a bottle.
HowDo
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: United Kingdom
Posted: 25th Jun 2008 12:16
Sunflash I think you need to add curvevalue or angle.

as the x and y position you give it,will just make strainght line to it. so by adding curve value or angle or both it will then go to the next position. then when reached you give it a new value to go to.

some like thing this,(half code and half thinking)

if AI get Entity Is Moving Entity(ID)<>0

new_AI_posx= curvevalue(x,last_AI_posx,speedvalue)
new_AI_posy= curvevalue(y,last_AI_posY,speedvalue)
new_AI_angx= curveangle(x,last_AI_angx,speedvalue)
new_AI_angy= curveangle(y,last_AI_angY,speedvalue)

last_AI_posx=new_AI_posx
last_AI_posy=new_AI_posy
laat_AI_angx=new_AI_angx
last_AI_angy=new_AI-angy
update AI position id new_AI_x,new_AI_y,0
update AI angle id new_AI_angx,new_AI_angy,0
endif

Dark Physics makes any hot drink go cold.
Sunflash
19
Years of Service
User Offline
Joined: 28th Jun 2005
Location: Seattle, Wa
Posted: 26th Jun 2008 09:25
Oh, great point. Although for what I need, that detail isn't necessary. Thanks though, I'll try to keep that in mind for my next project!

I did however have an error in the finished code solution I posted. I randomized the angle I used in the Sine/Cosine command to find both X/Y coordinates. This is a problem because it won't actually tell it to move within the circle, but it will move within a box, basically a circle with corners (which is a box). This is because if the max rediuses are randomly selected as coefficients of the Sine/Cosine commands, and the right angles are randomly selected, the point generated may actually reside in one of the corners, on the outside of the circle. To fix this, the ange randomly selected must be the same used by BOTH the Sine/Cosine commands. This will keep the finished point WITHIN the circle. Here is the finished code:



Mountain Dew, happyness in a bottle.
HowDo
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: United Kingdom
Posted: 26th Jun 2008 13:11
amazing what putting one value in the right place can do to your code.

Well done, should make a mini demo of this and put in code snippets.

Dark Physics makes any hot drink go cold.
Sunflash
19
Years of Service
User Offline
Joined: 28th Jun 2005
Location: Seattle, Wa
Posted: 26th Jun 2008 20:18 Edited at: 26th Jun 2008 20:26
Sure, here we are, t3h c0d3z for everyone!

The example makes a circle with the origin at the center of the screen. It then draws a line from the origin, to the cursors location. If the cursor is outside the circle, the line is halted on the line edge.

Cool notes: includes pythagoreans distance code, and finds the angle between two points using ATanFull(distanceX, distanceY)



This sample creates a circle at the center of the screen. It then randomly generates 1000 dots INSIDE the circle each frame. Try it out, if you don't understand whats going on, try switching a few values.



This example is the same as the last one, only the circle will slowly grow, but the code will function normally. The same technique could be applied to the first example easily


EDIT: Forgot to give a general apology for my lacking Trig. I just started class two days ago, and am LOVING it!! It's a gamers dream really... That and Physics.

Mountain Dew, happyness in a bottle.
sindore
20
Years of Service
User Offline
Joined: 2nd Jul 2004
Location: Bedfordshire, UK
Posted: 27th Jun 2008 23:37
@ Sunflash

Quote: "I just started class two days ago"


are you doing a course on gaming?

Quote: "should make a mini demo of this and put in code snippets."


@ HowDo

are you going to add a demo?

if so are you going to post here or just add it to the code snipit?

soul sucking devils, twisted body of the damed, slivering slim drips from every poor, sin licking at your ears, and the smell stinging your eyes, and if you don't like it, get out of my kitchen!

Login to post a reply

Server time is: 2024-11-24 23:34:17
Your offset time is: 2024-11-24 23:34:17