Simplistic pathfinding

A forum to share your demonstrations stacks, fun stacks, games, etc.
Post Reply
User avatar
tperry2x
Posts: 1991
Joined: Tue Dec 21, 2021 9:10 pm
Location: Somewhere in deepest darkest Norfolk, England
Contact:

Simplistic pathfinding

Post by tperry2x »

Here's something for anyone's amusement.
I'm sure it can be improved upon, by anyone with a grasp of basic maths. (not me).
Seems to pick it's way around the green obstacle most of the time. (Let's generously call that a hedge)

Drag the X (x marks the destination), and the A is the player / zombie / (whatever), which has to get to the X.

Choosing the pointer tool stops everything in it's tracks. Alternatively, you can also drag stuff around while it's running (non blocking)

All the script is just in the two buttons shown.
simplistic-pathfinding.png
simplistic-pathfinding.png (17.26 KiB) Viewed 1394 times
simplistic-pathfinding.oxtstack
(11.98 KiB) Downloaded 47 times
xAction
Posts: 285
Joined: Thu Sep 16, 2021 1:40 pm
Contact:

Re: Simplistic pathfinding

Post by xAction »

Doesn't work with multiple objects.

1. grab the SLOPE function from the 3D ShuffledBoard example
2. slope a line from the seeker position to the target

3. check if there are points in the slope that are in the rect of any of all the objects
repeat with i = 1 to number of graphics of this card
put short name of graphic i of this card into tObstacle
if short name of graphic i of this card is "ObjA" then next repeat
if short name of graphic i of this card is "ObjB" then next repeat
if short name of graphic i of this card is "tLine" then next repeat
-- do your slope points check
end repeat
4. can't get there from here? Pseudo code
put y of target into targetY
if the target x < seeker x then
add gridUnit to targetY
put (left of your game area) , targetY into NewSearchPoint
else
subtract gridUnit from targetY
put (right of your game area) , targetY into NewSearchPoint
end if
5 slope test to NewSearchPoint until you find no slope in a rect

6 at some point if you run out of options in one direction flip the search the other way.

At each solved waypoint, search for the target again to get the next way point.

Get all the waypoints before moving.

I'd do this myself but I've been up way too long, and I've been making so many blunders for hours, and your code is not mine so I don't know where to start.
'
Good start!
xAction
Posts: 285
Joined: Thu Sep 16, 2021 1:40 pm
Contact:

Re: Simplistic pathfinding

Post by xAction »

Another obtion instead of having to write a bunch of if...then...next repeats
Get a list of all objects, filter out the not-obstacles and only scan those rects for a slope, can get all the rects once and scan that list, could even split the lists to "left" and "right" sides to shorten the scan time.
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests