character following drawn path

Get help using Construct 2

Post » Fri Feb 06, 2015 1:29 am

Hello,

Using the canvas plug in I have created an event that allows me to draw a line with the mouse, however I am still having trouble getting the character to follow that path after I have drawn it. I have watched several tutorials and have not gotten the desired effect. I was wondering if there is a way. I am sure it is with path following, but I havent been able to get that to work either.

Thank you
B
6
S
2
Posts: 19
Reputation: 1,389

Post » Fri Feb 06, 2015 3:24 am

have you tried using the custom movement behavior ???
but I need a capx file to be sure
B
5
Posts: 60
Reputation: 345

Post » Fri Feb 13, 2015 3:13 pm

I have uploaded the capx file. When you play it in the browser, I have the ability to drawy on the screen with the mouse. I have tried to use the path following behavior, with a "wait" condition, but that didn't seem to work. I am thinking itr is because I am using the canvas plug in, but I dont know why other behaviors wouldn't work on a canvas?

Thanks for your time
You do not have the required permissions to view the files attached to this post.
B
6
S
2
Posts: 19
Reputation: 1,389

Post » Fri Feb 13, 2015 10:22 pm

It's definitely non-trivial, and I haven't looked at your capx. But basically you'll need to lay down a series of points as you're drawing, and have the character follow those points one by one.
B
90
S
30
G
24
Posts: 3,189
Reputation: 32,465

Post » Sat Feb 14, 2015 1:12 am

Well, I am using the canvas plug-in. I am able to draw the lines on the screen. Every tick the system creats an object which is my "line" object, from dot 1 to dot 2. I have fixed it now where on left button released, the character will find a path to mouse.x mouse.y. The character gets there fine, but it doesn't follow the exact path. I am thinking it needs to be that the character finds the first "line" object created, follows it, as it hits that object, it destroys it, and the character looks for the next line, and so on, until it reaches the end. I...hope this is making sense.

In a nutshell... the character has to follow the points, and i do have those points on the screen, because they are drawn... but the character does not follow them, he makes his own path to find the end.
B
6
S
2
Posts: 19
Reputation: 1,389

Post » Sat Feb 14, 2015 7:11 am

Here's a possible way to do it (these aren't actual events, but show my logic)

On reached point: destroy point

Every tick: path to *least recently created* point.

All you need to do then, is track the least recently created point. That's fairly simple to do by giving all the points an instance variable called 'age' or something. Then, whenever a new point is spawned, increase the 'age' of *all* the points.

Does that make sense?
B
90
S
30
G
24
Posts: 3,189
Reputation: 32,465

Post » Mon Feb 16, 2015 3:53 pm

Oh yes, i follow what you are saying absolutely...but code has a good way of not doing good, even if it sounds right, haha but i will definitely try that! Stay tuned for an update. I have tried using the "line" point, but maybe if i give the line the instance variable, I will try that. Perhaps a global variable would work just as well? hmm...
B
6
S
2
Posts: 19
Reputation: 1,389

Post » Mon Feb 16, 2015 5:09 pm

Okay, I have two sprites, which create a path in between them. This path is called "line 1" The character will find a path just fine, to the two dots... but it will not find a path to "line" I am thinking because there are spo many "line 1's" on the layout, so the character doesn't know which one to go to. I need a way to have each line created have a different name, I think... if that makes sense..
B
6
S
2
Posts: 19
Reputation: 1,389

Post » Mon Feb 16, 2015 5:16 pm

Just give them instance variables.

ie

line1.linenum

linenum instances variables could be 1,2,3,4,5,6,7,8 etc


And for the other matter

Add pathfinding to the vars


searchvariable = 1


function "findpath"
event
pick all line1,
pick by eval line1.linenum = searchvariable
action
find path line1.X line1.Y

event
on path arrived
action
add 1 to searchvariable
call "findpath"


event
on path found
action move along path


Simply call "findpath"

and it will find paths to the line1's in consecutive order based on their instance variables
Who dares wins
B
50
S
10
G
10
Posts: 1,728
Reputation: 12,875

Post » Mon Feb 16, 2015 10:31 pm

The problem is, there are multiple "line" 's. I have an instance variable for the line called age. I have each time the a line is created it adds 1 to the instance variable age. I guess I need an expression for the character to know, that the first line has instance a different instance variable then the next "line". Maybe I am not just explaining good enough...
B
6
S
2
Posts: 19
Reputation: 1,389

Next

Return to How do I....?

Who is online

Users browsing this forum: Braus, pinoyaida and 5 guests