Object following a path drawn by the player

Get help using Construct 2

Post » Fri Aug 17, 2012 4:27 pm

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 :-)ForlornCreature2012-08-17 16:55:23
B
5
S
1
G
1
Posts: 43
Reputation: 888

Post » Fri Aug 17, 2012 5:45 pm

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
B
54
S
28
G
18
Posts: 1,520
Reputation: 24,990

Post » Sat Aug 18, 2012 12:15 am

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,

-Adam
B
85
S
31
G
14
Posts: 106
Reputation: 16,430

Post » Sat Aug 18, 2012 3:34 pm

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?
B
5
S
1
G
1
Posts: 43
Reputation: 888

Post » Sat Aug 18, 2012 3:35 pm

I'm really having trouble trying to get an object with a platform behavior to move along the line.
B
5
S
1
G
1
Posts: 43
Reputation: 888

Post » Sat Aug 18, 2012 5:52 pm

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

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. ForlornCreature2012-08-18 17:53:18
B
5
S
1
G
1
Posts: 43
Reputation: 888

Post » Fri Feb 07, 2014 3:56 pm

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.

B
2
Posts: 1
Reputation: 152

Post » Fri Feb 07, 2014 4:01 pm

@kichi3d

Would following the link in the second post work for you?
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
53
S
16
G
8
Posts: 6,157
Reputation: 19,744

Post » Fri Feb 07, 2014 5:44 pm

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.
B
49
S
11
G
10
Posts: 1,833
Reputation: 14,418

Post » Fri Feb 07, 2014 7:11 pm

This clip is from second post link (actually from this capx https://dl.dropbox.com/u/8367729/construct/example/rocketFollowPath_fixed.capx)
I have hard time to understand these two steps:
http://sdrv.ms/LXhXwo
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?

Thanks in advance.Ecculi2014-02-07 19:13:57
B
6
S
2
Posts: 6
Reputation: 608

Next

Return to How do I....?

Who is online

Users browsing this forum: jeffige, TheHat, Yahoo [Bot] and 1 guest