|
-
[RESOLVED] Avoiding an obstacle on your way to target.

My character is moving to the money, a little step every second.
Every tick - he is casting a beam towards the money, to check for collision.
He needs to steer away from possible obstacle - but, he needs to continiue on his way to money.
Best trajectory to do his is moving along to the red dot, but I just cannot wrap my head around this one - how do i calculate it's position?
It took me a really long time before I crawled here, for help. I surrender now.
Anyone? Please?
-
Senior Member
If the obstacles and target are not moving its probably best to set up red dots manually as nodes for path. Then you can use simple and well-researched path-finding algorithm like A-Star from node to node.
In case of dynamic environment, you could try something like this:
*cast beam to target, if does not hit any obstacles, move to target
*if beam hits obstacles, cast 2 new beams with length of distance to target
*one new beam 1 degree clockwise from original, other new beam 1 degree counter-clockwise
*if both new beams also hit obstacles, cast new beams 2 degrees away
*continue until one of new beams misses the obstacles
*pick that beam and move in that direction couple of steps
*after some distance start over with beam to target
-
Thanks for your insight.
I got this figured on my own though, yesterday before going to sleep.
I rotate my beam -X degrees, where X is obstacle radius based. somewhere close to 40 degrees(Hacky). Most problematic was to implement this. I found some "rotate point around point" class on the net (http://www.tdotblog.info/?q=node/16) and used it.
Cause it's seems I just cannot rotate my beam (sprite made with drawingAPI) accordingly.
Your method is more precise though. If only I knew simplier way to "cast 1 degree away". How do you calculate that new coordinate? I know the answer sits in that class I found, but I'm a sucker at math.
-
Pumpkin Carving 2008
Code:
Point newPoint = rotatePoint(targetPoint, originPoint, oneDegree);
The 'Boose':
ASUS Sabertooth P67 TUF
Intel Core i7-2600K Quad-Core Sandy Bridge 3.4GHz Overclocked to 4.2GHz
8GB G.Skill Ripjaws 1600 DDR3
ASUS ENGTX550 TI DC/DI/1GD5 GeForce GTX 550 Ti (Fermi) 1GB 1GDDR5 (Overclocked to 1.1GHz)
New addition: OCZ Vertex 240GB SATA III SSD
WEI Score: 7.6
-
Err.. I knew how to use that class method. I just could not understand how it operates.
anyway I found the way in the Math section of forums. It was the basic stuff, which makes me ashamed of myself, cause I've read a book on this one year ago.
newPoint.x= originPoint.x + Math.cos(degrees*Math.PI/180) * distanceToObstacle;
newPoint.y=originPoint.y + Math.sin(degrees*Math.PI/180)* distanceToObstacle;
Anyway, thanks for "cast 2 new beams with length " idea, Tonypa. Otherwise it looked silly, when my char ran around obstacle always in clockwise direction, even when it was not the shortest way.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|