[SOLVED] Adding points when one object successfully jumps over another


Hey friends,

I'm making a game similar to the T-Rex when Google can't connect page. Couple of people on a tandem bike jumping over rocks basically. I'm trying to figure out what the best way to code points scoring would be. Here's an example image:


Basically at that moment where they successfully make it over the rock, they should score points. I tried

if instance_exists(o_obstacle)
    if o_player.x == o_obstacle.x then points++;
which didn't work. I'm started to think I should build out some lengthdir_y logic but I feel like I must be overcomplicating it.

Any ideas or pointers would be hugely appreciated!


Just track when o_player is to the left of the obstacle, and then when it's on the right, score and tell that obstacle not to do it again.


For reference, if o_player.x == o_obstacle.x then points++; doesn't work because your x values are usually non-integers depending on your movement system, and so may almost never line up. So if you wanted to do something like comparing x or y values, you would want to use round/floor/ceil, possibly in combination with mod/div.


To elaborate on what's been said, you can give the obstacle object a variable which tracks if it's been scored yet, say scored = false.
Then if scored is false, compare the obstacles x position to the bikes, and if the bikes x is greater, allocate the points, and set the scored variable on the obstacle to true, so it won't be processed again.
Something like this in the bikes step event :
with(o_obstacle) {
  if !scored {
    if x < other.x {
      scored = true;


šŸ§ *penguin noises*
GMC Elder
The genre is called "endless runner", knowing that might make it easier to look for examples and inspiration.

The easiest way to do this in GM is to make invisible marker objects (make them visible while testing to make it easier to see what's happening, though) which are spawned together with obstacles, and get the same speed as the obstacles. When the player collides with a marker, it is destroyed and they get points. Obstacles that needs special treatment (e.g. limbo-sliding under something instead of jumping over it) could have a smaller marker that only covers the important bit of the hitbox. (And don't forget to destroy markers that goes offscreen to avoid memory leaks)


Better be other.points++ unless every obstacle is storing its own score.
Possibly. The way he set it up in the example made me think he had used the obsolete globalvar to initialise points, or had points in another object, as it mentioned both objects as accessors.
Last edited: