Paths?

For questions about using Classic.

Post » Sat Aug 08, 2009 2:59 am

I was wondering if there was a way to set a predefined path in Construct. Let's say for example I have a path that isn't straight from A to B and want the player to move towards B along the path if I hold the right arrow down, and vice-versa for the left arrow.

Is this possible?
B
2
G
3
Posts: 68
Reputation: 986

Post » Sat Aug 08, 2009 3:00 am

there are ways to do something like this
how were you planning to define the path though?
Spriter Dev
B
87
S
21
G
12
Posts: 3,240
Reputation: 16,461

Post » Sat Aug 08, 2009 3:05 am

[quote="lucid":2a2vdn09]there are ways to do something like this
how were you planning to define the path though?[/quote:2a2vdn09]

I'm not sure... in GameMaker there is a path editor where you can just define points and reuse it as many times as you want. If such a feature doesn't exist, it'd be nice to add one!
B
2
G
3
Posts: 68
Reputation: 986

Post » Sun Aug 09, 2009 5:52 pm

Object path behaviour has been discussed, and I believe it will be added at some point, but until then what most of us do is:

1. Create some sprites to use as your waypoint objects. Usually a small circle or an "X" will do.

2. On the startup, you can use a loop to set a private variable, say "pointnumber" for example, to each point based on position, or depending on the path (IE straight line, around in circle, etc) you could use the UID of each object.

3. Get enemy or whatever you want to follow the path, make it have a "destination" variable. On startup if will look for "pointnumber" 1, then on contact with point 1, its destination will change to "pointnumber" 2, etc etc.

That's probably the best way. You can also make it change speed, size, animation frame, etc based on its destination variable.

~Sol
Tired of crappy file hosts that are crappy? Get DROPBOX - https://db.tt/uwjysXJF
Moderator
B
45
S
17
G
37
Posts: 2,853
Reputation: 25,966

Post » Sun Aug 09, 2009 7:51 pm

Or, well, if you've got a way with numbers, you can use polinomial functions to define the path. Y'know, splines and stuff.
B
62
S
21
G
12
Posts: 1,910
Reputation: 13,155

Post » Sun Aug 09, 2009 9:32 pm

bezier curves do this nicely

simply set position to
X= cubic(p0.x,p1.x,p2.x,p3.x,variable('t'))
Y= cubic(p0.y,p1.y,p2.y,p3.y,variable('t'))

the p#'s are sprites which define the paths points. p0 would be the point the path starts at, p3 would be the one it ends at. the other 2 control the curvature of the path like so

as you can see t is a value which when changed moves the paths returned position along. it should be a number from 0 to 1. 0 meaning its at the complete beginning of the path, 1 meaning its at the absolute end. 0.5 would mean the center. imagine if you multiplied the number by 100 it would be the percent moved along the path. so 0.25 would be 25% and so on.
if you would like to move your object back and forth along the path at a certain speed simply add a small number like 0.01 to the t value. so it will take 100 frames to move it from p0 to point p3.

a value less than 0 or greater than 1 will simply move the object to a position that would exist if the curve were to continue at its current amount of deviation
B
52
S
7
G
6
Posts: 1,945
Reputation: 7,610


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 1 guest