Pathfinding for ships

0 favourites
  • 12 posts
From the Asset Store
26 pixel space ships of Humans and Invadors including regular and boss space ships.
  • Hi guys,

    Apologies as i have another question regarding pathfinding or flightpath for ships.

    I'm creating a SHMUP and so far from my experience the hardest part for me in developing this game is bullet patterns and flight patterns.

    Right now i'm trying to create flightpaths for my enemies and i have been trying and reading some of the other behaviors in which is in this forum.

    I have currently added in the events from R0J0hound pathfinding capx and am really happy with this cause the event made my sprites movement looks realistic as in the gif below.

    But i encountered 3 problems:

    1) I noticed that with the "flight points" added in as indicated with the light green boxes i can't really "tell" my sprites to actually fly from point A to B then to C, they seemed to fly around to random points .

    2) The event will grab all sprites which are in the event sheet itself regardless if they are in the game area or not, how do i have the sprites to fly around when only in the game area?

    3) I tried to set "System > Create Sprite > On "Game" Layer so that after creation, the sprite will start pathfinding and moving from point to point but it doesn't work, the sprite just spawns and stays there not moving.

    Below is my event list:

    I toggled off the spawning cause it doesn't work.

    Basically what i want to do is "Spawn Enemies" > Fly (Pathfinding) > Point A to B

  • This is the said thread for the pathfinding

  • I haven't looked at the file but its probably using the objects IID as the order of waypoints.

    I think R0J0hound already answered this question in that thread.

    [quote:ll7i8tqv]Yes, that is possible, but instead of using the IID to access the points store all the points in an array.

    Then do these changes to the expressions:

    p(n).x -> Array.At(n % Array.Width, 0)

    p(n).y -> Array.At(n % Array.Width, 1)

    p(n+1).x -> Array.At((n+1) % Array.Width, 0)

    p(n+1).y -> Array.At((n+1) % Array.Width, 1)

    p(n-1).x -> Array.At((n-1) % Array.Width, 0)

    p(n-1).y -> Array.At((n-1) % Array.Width, 1)

  • Ethan thanks for your reply!

    I can't do arrays at the moment as my version right now is currently free. My target is to at least finish up the 1st level of my game before i make the purchase.

    If i were to not use R0J0hound's events and use the custom moving events instead, my sprites will end up moving in a very rigid fashion, is there anyway?

  • I'm pretty sure you can use arrays in the free version

  • MythStylz

    Yes i tried and it can be used, my bad i think i mixed it up with families.

    I don't really know how to add those into arrays thou. Is there another way for pathfinding but with the fluid movement from R0J0hound's events?

  • Sorry all, gonna bump this. Currently at a loss right now

    Been reading all day in the forums, have tried litetween, pathfinder, custom movement, bullet, moveto behavior by rex. I cant get any of them to work.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • SO I haven't done it but here's the tips I got:

    1) I noticed that with the "flight points" added in as indicated with the light green boxes i can't really "tell" my sprites to actually fly from point A to B then to C, they seemed to fly around to random points .

    They seem to be flying in a circle in the gif, as mentioned earlier the IID (Instance ID) is being used, so that the first one created on the screen will be A, B, C etc... If you want more control over that arrays are really simple... Put the position of your green spots (click on them and look in the properties bar) into the array, your Array is gonna be as wide as the number of points you have minus 1, (because it starts at 0), Height is 2 for each coordinate and 1 for depth (which you won't use)

    So Points x 2 x 1 will give you a table that looks like:

    (Point 1 X, Point 1 Y)

    (Point 2 X, Point 2 Y)

    ETC...

    Now to insert the points into the array is a little code: add action : Array: Insert (Point 1 X) at 0 on X axis, Insert (Point 1 Y) at 0 on Y axis, Insert (Point 2 X) at 1 on X axis, Insert (Point 2 Y) at 1 on Y axis

    That should solve that with combined previous stuff ^^

    2) The event will grab all sprites which are in the event sheet itself regardless if they are in the game area or not, how do i have the sprites to fly around when only in the game area?

    Your gonna want to give the sprites a instance variable (preferably a Boolean: something simple like "active") When it's on the code uses it, when it's off it isn't affected by code. Then your going to have to have some event Trigger to make them active. you could also start the game having a few active and a few inactive, and when you kill one a new one becomes active. But yeah just add the condition that when boolean is on it uses that code.

    3) I tried to set "System > Create Sprite > On "Game" Layer so that after creation, the sprite will start pathfinding and moving from point to point but it doesn't work, the sprite just spawns and stays there not moving.

    So it's only running the code in order from top to bottom: I.e. it grads all the current Enemy4, then if you create a new one it won't grab that. You can add the actions to the Enemy4 after you spawn it, so after this creating sprite action you have, just repeat... ( this may mess with your previous ships, I haven't tried I don't know, if it does make a t2 and a n2 global variable and get 2 going on.)

    What you can also do is add a system>for each step to the for each enemy4 condition (this is also where you should add the boolean condition.) It may work, or it may just constantly set the t and n to the same thing... IDK, try it out. Come back if neither of these work to your suggestion: put what you've done and hopefully somebody smarter than me will awnser

  • Wait a second, instead of the Insert command, use the Set at X and Set at x,y commands their a little easier to grasp when your first doing arrays.

  • might help, or at least give you another idea.

    https://db.tt/lMIxlRMH

    edit (9am sat) - I've just had an epiphany - "I'll be back !"

    edit my special offer from dropbox has come to an end - I will need to reorganise my links and repost when I get organised

  • code is a mess but have a quick look at

    https://dl.dropboxusercontent.com/u/143 ... index.html

    you can move the points around, add and delete points. points can also move together (eg scroll down screen or rotate)

    is this something you would be interested in ?

    no plugins just c2

    edit my special offer from dropbox has come to an end - I will need to reorganise my links and repost when I get organised

  • RamPackWobble

    The link is currently down, no worries i will wait for your links to be backup again.

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