0 Favourites

change variable based on coordinates

  • Hello!

    In my game I have this bar, and a sphere. Whenever the sphere is over the bar, the player must press spacebar. But, I want to have the player to check if this bar is red or green. If it's red, he cannot press spacebar.

    My issue os That i need the bar to change colors when the sphere is about 100 pixels close to the bar. Problem is, the sphere can approach from left or right, and i can't calculate X that way.

    Glad if you could help!=D

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • You missed the CAPX ^^

    Do you want a simpler way? Make a check by overlapping with offset or, make a check with a invisible mask around and pinned to your bar.

  • In terms of performance, how wold the mask imply at this game?

  • what about checking distance between bar and sphere?

    distance(bar.X, bar.Y, sphere.X, sphere.Y) < 100 -> change color

  • what about checking distance between bar and sphere?

    distance(bar.X, bar.Y, sphere.X, sphere.Y) < 100 -> change color

    @shinkan It will check the distance only of the origin point, right?

    @Zerei the impact is near to zero, you can't feel the difference. I'm using it and it's rocking on my game.

    You should use square objects instead of complex polygons, because more points on the polygon issue on performance. It's better to check 10 objects with 4 points on their polygons instead of 2 with 20 points.

    This is my debugging interface, you can check all the collision masks, I implemented them on a single layout and did this layout check if it's on preview, if yes, it become visible, if not, invisible.

    [tube]http://www.youtube.com/watch?v=pJFQftlOdH0[/tube]

  • distance(bar.X, bar.Y, sphere.X, sphere.Y) - yes, from the origin point

    but you modified it as you want

    distance(bar.X, bar.Y-(bar.Height/2), sphere.X, sphere.Y) - this will check between sphere origin point and bar top center.

  • Thanks Guys! It really helped!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)
Similar Topics Posts Views Last Post
Unread hot topic Locked topic
195 16,197
Ashley's avatar
Ashley Construct Team Founder
Unread hot topic
102 6,402
Ashley's avatar
Ashley Construct Team Founder
Unread hot topic
0 Favourites
Grid based lighting/field of view
65 15,236
elwinalice's avatar
elwinalice