0 Favourites

# Object following a path drawn by the player

• 13 posts
• The concept of the game I'm working on features a mechanic that requires the player to draw out a path, then the object (or character) hops onto that path if it is close enough and follows along it in the same direction the player drew it.

So really, there are two things I'm struggling with here:

1. The player draws a path, with vector points with ascending variables for the object to follow. Paths disappear over time. I can draw a line by spawning an object on mouse click every tick, but it's fragmented and accumulates when you hold the mouse still.

2. The object has to detect if a vector of a higher value is within a certain radius (switching to newly drawn paths) and move to it at a steady rate, thus following the path laid out until it falls off the end. I tried using collision, but it's not really doing what I want it to do.

I've had a go at both of these things although I learned a bit of construct over a year ago, I can't quite work out how to get it to do what I want because of my limited experience.

BTW It's a game concept I'm trying to prototype for a friend :-)

• This thread might give you some ideas. Have a look at R0j0hounds capx:

http://www.scirra.com/forum/how-to-make-bullet-follow-the-line-just-drew_topic53718.html

• Off the top of my head, you may be able to use way points.

Basically, each second, the system create an object at your mouse pointer's (x, y). And gives it a variable number (I.e. called "WP"). Each time adding +1 to the value, so you are left with a series of waypoints with ascending "WP" values.

Your sprite has a variable, lets call it "Number". It compares the waypoints on screen and angles itself towards the waypoint if "Number" = "WP". It then moves at that angle. When your sprite collides with the waypoint, you add +1 to "Number", which means it then angles towards the next way point. And moves onward.

If there are now waypoints with the same "WP" values or less than "Number" then your sprite dies.

Each waypoint can also have another value which acts as a count down time, that when it is below 0, the waypoint is destroyed.

Each waypoint is 'invisible', so can't be seen when the game is played.

Hope that helps,

• Thank you so much ramones! That capx showed how to draw a really cool line, I've studied it and worked out how to do it myself now.

The movement in it however doesn't quite do what I want it to do. I will have a go at creating a movement event for the character using variables for each dash, but since this is a platformer I want my object to be affected by gravity when it comes off the line.

Should I use the bullet behavior once it's on the line and turn on it's gravity when it comes off? I also want it to launch a little bit when it flies off the end of path, so should I just be using the physics behaviour to make it gravitate towards each waypoint and switch to the next one upon collision?

• I'm really having trouble trying to get an object with a platform behavior to move along the line.

• capx

Woo! Got it working, although I need to find an alternative to destroying on collision, and dashes that are given time to fade out reappear for the object to pass through them <img src="smileys/smiley29.gif" border="0" align="middle">

A couple other things I can't implement-

The object carrying momentum as it comes off the line.

Only getting on a path if it is within a certain radius.

• Dear forlorn hello! did you resolve Object following a path drawn ? i am working in some thing similar but i need to move a plane follow a line.

did you have the example to post?

sorry mi english.

• Would following the link in the second post work for you?

• Just a random thought for another way to do this... have a grid of tiles (invisible) covering the layout, when the user draws a line destroy the tiles that they touched. Then use pathfinding to navigate your object through the newly cleared path. Of course set your pathfinding to either solids or custom object (the grid of tiles) and then just calculate the route through that cleared path.

• This clip is from second post link (actually from this capx dl.dropbox.com/u/8367729/construct/example/rocketFollowPath_fixed.capx)

I have hard time to understand these two steps:

What does that step 3 (blue arrow) do? I understand that it is some kind of loop which launches only when distance between dash and mouse is more than 20 and it spawn new dash, but I dont fully understand it meaning.

Also next step is also unclear to me.

Could someone explain those two steps?

• Has anyone figured this out?