Author |
Message |
munt4life
|
Posted: Sun May 01, 2011 9:56 am Post subject: following a path? help please :D! |
|
|
Hey i was wondering what i would have to do if im controlling a circle, and there is another circle, how would i get the circle to follow me, i am making a game where theres many obstacles and i was thinking in one part there would be a couple "monsters" chasing me, so depending on where i move they would go towards me as well. Any feedback would be helpful thanks! |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
A.J
![](http://compsci.ca/v3/uploads/user_avatars/119833057151651227b0d87.gif)
|
Posted: Sun May 01, 2011 12:39 pm Post subject: RE:following a path? help please :D! |
|
|
There are many ways one could implement enemy's chasing you. One naive way to do so is to have the enemies move towards your position at every iteration; to do this, you measure the angle at which the enemy needs to move at, and increase its x and y position (assuming this is a 2D game) accordingly. The downside of this method is that the enemies don't traverse around obstacles (instead they just try going through them).
To account for obstacles, however, you need to utilize a path finding algorithm. The one I recommend is the A* ('A star') algorithm (I'll leave it to you to read up on it). If you have any questions regarding it, feel free to ask us here. |
|
|
|
|
![](images/spacer.gif) |
munt4life
|
Posted: Sun May 01, 2011 6:05 pm Post subject: Re: following a path? help please :D! |
|
|
im assuming i need trig? |
|
|
|
|
![](images/spacer.gif) |
Insectoid
![](http://compsci.ca/v3/uploads/user_avatars/13760332514cbd0ce972eaa.jpg)
|
Posted: Sun May 01, 2011 6:21 pm Post subject: RE:following a path? help please :D! |
|
|
Yes. It's fairly simple though; since you're only making right triangles, you can get away with sine law. |
|
|
|
|
![](images/spacer.gif) |
DemonWasp
|
Posted: Sun May 01, 2011 6:42 pm Post subject: RE:following a path? help please :D! |
|
|
Actually, that particular algorithm doesn't even need sine law (and is faster without it). You just need to remember a few things about similar triangles and Pythagorean theorem. |
|
|
|
|
![](images/spacer.gif) |
Raknarg
![](http://compsci.ca/v3/uploads/user_avatars/3745510004d8be6689b92f.jpg)
|
Posted: Sun May 01, 2011 7:36 pm Post subject: RE:following a path? help please :D! |
|
|
or you could use
x + cosd (theta) and
y + sind (theta) |
|
|
|
|
![](images/spacer.gif) |
munt4life
|
Posted: Sun May 01, 2011 8:37 pm Post subject: Re: following a path? help please :D! |
|
|
ok so i tried doing something like
theta := arctan((y1-compy)/(x1-compx))
compx+=speedx(cos(theta))
compy+=speedy(sin(theta))
im getting an error on subscripts im pretty sure my math is right what should i fix? |
|
|
|
|
![](images/spacer.gif) |
A.J
![](http://compsci.ca/v3/uploads/user_avatars/119833057151651227b0d87.gif)
|
Posted: Sun May 01, 2011 9:02 pm Post subject: RE:following a path? help please :D! |
|
|
I thought you wanted to enemies that are chasing you to avoid obstacles. In which case, the method you are currently attempting to code (i.e. the first approach I described in my previous post) doesn't cut it. |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
munt4life
|
Posted: Sun May 01, 2011 9:05 pm Post subject: Re: following a path? help please :D! |
|
|
im trying to get the actual moving to work for now then after i will create restrictions i defined all those variables why does turing say speedx and speedy cannot have subscripts. |
|
|
|
|
![](images/spacer.gif) |
A.J
![](http://compsci.ca/v3/uploads/user_avatars/119833057151651227b0d87.gif)
|
Posted: Sun May 01, 2011 9:24 pm Post subject: RE:following a path? help please :D! |
|
|
Even if you have the enemies move towards you at every iteration in this fashion, you can't modify it to avoid obstacles as well; the enemies will just keep trying to come towards you even if there's an obstacle in the way. |
|
|
|
|
![](images/spacer.gif) |
munt4life
|
Posted: Sun May 01, 2011 9:26 pm Post subject: Re: following a path? help please :D! |
|
|
Could you please tell me why my code isnt working please so i could then move on to such a problem ![Razz Razz](http://compsci.ca/v3/images/smiles/icon_razz.gif) |
|
|
|
|
![](images/spacer.gif) |
A.J
![](http://compsci.ca/v3/uploads/user_avatars/119833057151651227b0d87.gif)
|
Posted: Sun May 01, 2011 9:44 pm Post subject: RE:following a path? help please :D! |
|
|
I don't see any code here to help you with/. |
|
|
|
|
![](images/spacer.gif) |
munt4life
|
Posted: Mon May 02, 2011 5:11 pm Post subject: Re: following a path? help please :D! |
|
|
anyone? |
|
|
|
|
![](images/spacer.gif) |
munt4life
|
Posted: Mon May 02, 2011 5:46 pm Post subject: Re: following a path? help please :D! |
|
|
k so now i have this
i tried a similar triangles method.
var bCoordx := x - compx
var bCoordy := y - compy
var d : real := Math.Distance (x, y, compx, compy) % computer finds out input position to determine where to move
var sx := 10 * bCoordx / d
var sy := 10 * bCoordy / d
then i have a bunch of stuff in a procedure blah blah so i have
drawfillbox (compx, compy, compx + 10, compy + 10, red)
how would i make the compx and compy change according to this? im confused please help ![Very Happy Very Happy](http://compsci.ca/v3/images/smiles/icon_biggrin.gif) |
|
|
|
|
![](images/spacer.gif) |
Raknarg
![](http://compsci.ca/v3/uploads/user_avatars/3745510004d8be6689b92f.jpg)
|
Posted: Mon May 02, 2011 5:53 pm Post subject: RE:following a path? help please :D! |
|
|
Depends on whether or not you want it to avoid obstacles. Is this the case? |
|
|
|
|
![](images/spacer.gif) |
|