Distance X only instead of X and Y?

I’m creating a gun laser system. It’s helpful for correctly aiming. It was added because you could buy helpers that assist in killing zombies, but you’d have a chance to forget where your character is. All humans are behind a wall and can only move up or down. They can only aim left too. The laser system is a light. When it touches an enemy, the laser should move back instead of going past them. I tried to accomplish this using thing.Distance(enemies), but it only moves back when the enemy touches the wall. Any way to only get distance from X?

bump, i need help pls

really i need it pls

You need to use mathematical expressions to calculate the distance on X axis only.
I’m not very good at math but this is one way to calculate:

floor(abs(object1.X() - object2.X()))

Create a scene variable call it distanceX for example and for value, enter the above expression
Replace object1 and object2 with the name of the two object you want to calculate the distance between.
This expression going to return the distance on the X axis between the Origin point (top left corner) of the two objects and assign it to the variable called distanceX.

Then you can use the variable to check distance

Scene variable distanceX <= 20 THEN do something