How do I add to value when moving closer to an object?

Get help using Construct 2

Post » Thu Apr 09, 2015 7:20 pm

Hi all,

I have a working progress bar but I can't figure out how can I add to the bar's value when my player is moving closer to another object. For example if my character goes further away from the object or just doesn't move then it wont add any value to the progress bar, and if the player moves closer to the object it starts to add value so when the player touches the object the progress bar is completed.

Any help :)?
B
3
Posts: 9
Reputation: 193

Post » Thu Apr 09, 2015 7:35 pm

Set the value of the progress bar using the distance system expression:
https://www.scirra.com/manual/126/system-expressions
currentDistance = distance(Sprite.X, Sprite.Y, Goal.X, Goal.Y)

If you want the length of the bar to be a percentage of the distance instead of the exact distance, on start of layout, set a variable originalDistance storing the distance. Then, when you set the width of bar, set it to currentDistance/originalDistance.
B
38
S
12
G
11
Posts: 331
Reputation: 7,712

Post » Fri Apr 10, 2015 10:50 am

FragFather wrote:Set the value of the progress bar using the distance system expression:
https://www.scirra.com/manual/126/system-expressions
currentDistance = distance(Sprite.X, Sprite.Y, Goal.X, Goal.Y)

If you want the length of the bar to be a percentage of the distance instead of the exact distance, on start of layout, set a variable originalDistance storing the distance. Then, when you set the width of bar, set it to currentDistance/originalDistance.



Thank you so much! that worked perfectly :D
B
3
Posts: 9
Reputation: 193


Return to How do I....?

Who is online

Users browsing this forum: mekonbekon, PreacH, tetuan, Yahoo [Bot] and 7 guests