# Simplest pathfinding around a tilemap track

Just started using Construct 2? Post your questions here

### » Fri Jan 08, 2016 9:51 am

I said I would NOT use it, so why give an example in which it is used?

So like I said, what you could do is check the distance to the currentdestinationnode (actually there is already an event doing that) and instead of setting the angle directly rotate 1 degree counterclockwise untill the new angle is reached..

Should be pretty easy to make..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

### » Fri Jan 08, 2016 6:37 pm

LittleStain wrote:I said I would NOT use it, so why give an example in which it is used?

So like I said, what you could do is check the distance to the currentdestinationnode (actually there is already an event doing that) and instead of setting the angle directly rotate 1 degree counterclockwise untill the new angle is reached..

Should be pretty easy to make..

Okay, I wasn't entirely sure if you meant it should be used or not, sorry. Why counterclockwise? What if the "bullet" is going from, say, 90° angle to 0°, wouldn't that be a clockwise rotation?

I'm trying to figure out how these expressions work, but it's slightly confusing to me how it's been written with distances and destinations, as I said, I'm okay with the basics, but detailed expressions are a bit difficult for me to manage, which is why I put this in the beginner's section, it's really not my strong point yet. Most things I try in C2 that aren't from the context menus tend to not work anyways, I usually forget to wait 0.1 seconds and events cancel each other out, so I'm sorry if I'm slow but I am trying to comprehend how these more advanced (to me) algorithms work.

As you say, there is the currentdestinationnode check (Turt.Pathfinding.NodeCount-1) but I have no idea how to gradually rotate the bullet when it's a) using a bullet behaviour and b) it's angle seems controlled by variables. I can probably get it if you can hint whereabouts I should put these events/conditions.
B
41
S
12
G
14
Posts: 1,124
Reputation: 11,286

### » Fri Jan 08, 2016 10:33 pm

LittleStain wrote:I said I would NOT use it, so why give an example in which it is used?

So like I said, what you could do is check the distance to the currentdestinationnode (actually there is already an event doing that) and instead of setting the angle directly rotate 1 degree counterclockwise untill the new angle is reached..

Should be pretty easy to make..

@littlestain Okay, I've managed to get it rotating with the rotate towards angle of motion, but obviously it only starts rotating when it's changed direction, whereas in order to be as effective as the pathfinding angle rotation, it would need to have a type of 'lookahead' whereby the sprite knows the next sequential direction it will be moving in, and could start rotating when it's within, say, 20 of the destination node. Is this possible using some of the data extracted from the pathfind?
B
41
S
12
G
14
Posts: 1,124
Reputation: 11,286

### » Fri Jan 08, 2016 11:17 pm

As stated before, what you'd need is an event "if within a certain distance of the destinationnode rotate towards the position of detinationnode+1"
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

### » Fri Jan 08, 2016 11:34 pm

LittleStain wrote:As stated before, what you'd need is an event "if within a certain distance of the destinationnode rotate towards the position of detinationnode+1"

https://www.dropbox.com/s/eytk0omy9wvlt0x/pst.capx?dl=0

I used this: but it never gets to the right angle, even though it tries?
B
41
S
12
G
14
Posts: 1,124
Reputation: 11,286

### » Sat Jan 09, 2016 10:02 am

Seems like you are almost there..
You could now add a "is not within angle" condition..

then add an else event and set the exact angle..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

### » Sun Jan 10, 2016 1:41 am

LittleStain wrote:Seems like you are almost there..
You could now add a "is not within angle" condition..

then add an else event and set the exact angle..

I'm just not getting this?
B
41
S
12
G
14
Posts: 1,124
Reputation: 11,286

### » Sun Jan 10, 2016 2:23 am

Okay, I kinda got it working (looks like it's got some serious racecar drift going on since it's faking the rotation and it has no effect on it's motion) but the last little booboo is it twists at the end of the path. Tried doing some offset checks, but it keeps twisting anyways. Any ideas?
B
41
S
12
G
14
Posts: 1,124
Reputation: 11,286

### » Sun Jan 10, 2016 3:21 pm

I think it's because the path find has to go to an image point, Finding the path to Finish.ImagePointX is saying ImagePointX does not take 0 parameters?

EDIT: did it with Finish.ImagePointX(0) but the sprite is still rotating on the finish of the path?

Here's a CAPX https://www.dropbox.com/s/p6ew8id1m9pus ... .capx?dl=0
B
41
S
12
G
14
Posts: 1,124
Reputation: 11,286

### » Sun Jan 10, 2016 8:30 pm

Well, like in the bulletevent, you should check if you're not at the last node, because destinationnode+1 doesn't work there..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

PreviousNext