Make a spider character follow a spider web, to reach to its prey, using the shortest path?

I tried to do this by using link paths and obstacles, pathfinders and collision masks. But the spider doesn’t follow the cob web to reach its prey. It goes around the web or either it doesn’t move at all.

What I wanna do is create a game like in this video.

Any advice is highly appreciated.

1 Like

By “link paths” do you mean this extension?
https://wiki.gdevelop.io/gdevelop5/all-features/extensions/linked-objects-tools/

1 Like

That’s an interesting challenge.

The link path finding seems like the best choice. The problem is linking hidden nodes since it normally links to a grid.

Using hidden nodes and the collision with the web sections seems to be the key. You can select the current colliding node.

Spider is in collision with node
Web is in collision with node

You could then use for each web object and check which nodes the web objects are colliding with while ignoring the current node either through an ID or use an object variable like currentNode and set it to true, you could then filter that node out by using currentNode of object is false. you could then choose a random node and tween the spider to it.

To use the linked path finder, you would need 2 different node objects per node because you can’t link instances of the same object to each other. You need a 2nd object.

(Say nodes was a group with node1 and node2)

You could use a similar approach.
for each spider object
–spider object in collision with nodes
----for each node1
--------link node1 and node2

You could then try to move the spider to the player or a random node using the link path finder.

Other options. Manual links through IDs.
Put a point on each end of a web piece. Pick a random colliding web piece and tween to the opposite end based on the fathest object point.

This is all just ideas. Ramblings. Maybe they’ll work. Maybe they’ll trigger another idea. I’m better when I’m at my PC and I can try things. If I experiment with the concept, I’ll post any positive results.

Yes. That the one. I tried it. But didn’t success.

Wow. Seems like there is lot of work to do. I will try this and reply if I succeed.
Thanks a lot :hugs:

1 Like

It might require a bit of setup but once setup it shouldn’t require a lot of events and it should be pretty automatic and reusable for any configuration.

Finding the shortest distance between 2 points on a web or network is a fundamental concept in graph theory and can be solved using Dijkstra’s algorithm. Here’s a link to a website describing it and a number of coded solutions (including Javascript, which you could implement in GDevelop)

Flag all that, @Keith_1357 has a much better solution using the Link Tools extension further down.

2 Likes

This was one of my ideas. While I think the link pathfinder or something else would be better, I still wanted to share it. I love the simplicity,

Try me: Everything is draggable. There needs to be a circle on top of 2 web pieces. Dead ends don’t work well.
https://games.gdevelop-app.com/game-ffcd8117-5454-438c-9987-4e7c0a1fc5a9/index.html

project: (click the green [code] button and [download zip] )
https://github.com/doug13579/gdevelop—spider-web

4 objects, all but the button have the draggable behavior, the spider also has the tween behavior, the node object has a Boolean named visited as a way to prevent the spider from moving immediately backwards.

I managed to get the spider to work with the linked pathfinder. I based it on an existing project, so it was easier than I thought.

Try me: The spider and the X target are draggable. Then click move.
https://gd.games/keith_13579/linked-tiles-12-13

source:

To remove a web the matching nodes would have to be unlinked. I didn’t test it but I think it could be done in the reverse of how it’s set up. Before deleting the web object, pick the nodes it’s colliding with and unlink them. It might not be all of the nodes though. Not the staked ones but the links between the distant nodes. IDK, I’d have to test that part. The web object itself is just visual. It serves no other purpose except for picking the nodes for setup.

4 Likes

This is my latest version and maybe my last. It has a demonstration of most features. I added 3 text objects. (show path status, reachable and number of links) Since the nodes work in pairs, there’s a node1 and node2 in the same location. So, each node will have at least 1 link.

Nodes the spider can reach are changed green, the non-reachable are turned red.
You can delete web sections by pressing the right mouse button.

try me: (right click deletes web sections)
https://gd.games/instant-builds/3ee79340-b1eb-4bdc-8971-716d42afeee4

source: (I kept each version in its own GitHub repository
https://github.com/doug13579/gdevelop-spider-web-3-linked

1 Like

This is genious :hugs: Thank you for this reply.

I tried to adjust this code to make the spider move one node at a time.
When I delete a web, spider moves towards the target by one node and stops there.
After I deleted another web, the spider moves again by one node.

To do that, I used “start timer” event and after timer reached 1 second if the spider collided with a node the " stop the object " event starts and the spider stops on the node.

However the issue is, after the spider stopped for the first time and when I delete another web, the spider moves back to the starting node. And this back and forth movement continues.

Any idea to fix this.

I can’t figure out how to move just one node toward the target. I can pick the connecting nodes based on the current spider condition but I can’t tell which node is closer.

This test uses a 2nd target as sort of a temporary target with a second test button.
The take into account conditions picks all of the nodes that can be reached from in this case the spider. Since there’s already a node where the spider is, it uses reached in 2 links. It then picks a random link after filtering out the nodes the player is in collision with.

If the spider moves to the wrong place, it’s probably moving to its previous link location. You need to unlink the spider from all other objects first and when the target object moves that needs to be unlinked first as well. Otherwise, the objects are linked to multiple nodes.

I’ve tried to do it in another way but for some reason it skips nodes. I can’t remember why. There’s something I’m missing. I don’t know if I’m creating the wrong or too many links. It needs to be compared to the way the grid links are created.

In theory this should work but it’s inconsistent. Sometimes it skips a node. If I can figure out why. I’ll post it. Your way might work as long as you unlink the old objects from the spider and/or targer.

I think part of my problem is the spider isn’t always starting exactly on the node. So, sometimes the first node (or node 0 since nodes like arrays start at 0) is the one the spider is almost on. So, it needs to go to that node first. And other times node 0 is the next node because it’s already on the one node. The same issue seems to apply to the last node.

Edit: I just realized why this doesn’t work

When I was relinking the spider, I was using spiderTargetGroup is inside It should be spider is inside It was linking the spider to the target instead of the current node.

This works:

My issue with the spider object not be exactly at the position is my use of put object around
Even using a value of 0,0 for angle and distance, there’s a floating-point error. Meaning sometimes it was putting the object at say 100 and other times it was 100.000000123

The fix for that is using move to position x,y instead of put around object.

example:

My project is currently a mess. I added a bunch of things to debug it. After I clean it up, I’ll upload my current version to GitHub.

2 Likes

Ok, I cleaned up my events and made some minor changes.

try me: spider and destination X are draggable, the web parts can be deleted with a right click
https://gd.games/instant-builds/5e1c5139-af90-4f18-b9cc-8fb2d35fb4f1

project:
https://github.com/doug13579/gdevelop-spider-link-pathfinder-2024-3

2 Likes

Thnx for the quick reply. Now I’m trying to use multiple targets and tweak this. This project taught me many new concepts.
Thank you again keith.

1 Like

You’re welcome. I had fun as well. I love the concept. It was new to me as well.

2 Likes