character following drawn path

1 favourites
From the Asset Store
You need this package if you want to program a Street Fighter or battle game.
  • 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

  • have you tried using the custom movement behavior ???

    but I need a capx file to be sure

  • 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

  • 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.

  • 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.

  • 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?

  • 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...

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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..

  • 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

  • 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...

  • I have included a snapshot of what I have so far. This is just one of the many examples of what I have tried so far. I believe that the character, sprite two, is trying to find a path to multiple "line" 's. I know that the character has to find a path to the earliest "line" I know the "line" should have an instance variable. It does have one starting at zero. I had the line add "1" to the instance variable everytime a new "line" was created every tick. This did not work unfortunately. I can include the most recent capx file if necessary. This is the only part I am struggling with. After this I know how to do everything else that I am looking for. I really appreciate everyone's help. I have coded a couple games before, I just am not sure why I cannot wrap my head around this concept.

  • Add second instance variable, indicating which click/touch cycle it is in.

    Have a global or dedicated object var increment upon releasing mouse button or on touch end, combine with the add 1 to age, and you will have have sets of ages.

    on touch/click end add 1 to global var clickcycle.

    on line create, add 1 to line.age, plus set line.clickcycle to clickcycle.

  • I am still having trouble. I have it where my drawn line has an instance variable. Every tick the system adds 1 to the "Age" of the instance variable. The character is still unable to find the path to the first line. I have included my capx file. I think the character needs to find a path to line.age"number". which would be the first number, on found that line would be destroyed, and he would look for the next one automatically, which would simulate following the path I have created. I just know I am missing something.

  • I.......I just know I am missing something.

    MoveTo Behavior

  • Hello again,

    This is close to what I am looking for. I have installed the move to behavior, and it works, but... it is not moving to where I want. It is not following the drawn path. I believe, like everyone has been saying, it needs to involve instance variables, and I have one for the object I want the character to move to, I just don't believe it is set up right, and I am having difficulty doing that. I know it I can have it to where the character finds a path or moves to the line with the first instance variable, destroys that then looks for the next one in consecutive order, I am just having difficulty.

    Thanks agian for all the help!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)