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

0 favourites
  • 3 posts
From the Asset Store
This is a single chapter from the "Construct Starter Kit Collection". It is the Student Workbook for its Workshop.
  • 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 ?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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.

  • 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 <img src="{SMILIES_PATH}/icon_e_biggrin.gif" alt=":D" title="Very Happy">

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