Is it possible to compare a position parameter with numerical value?

Attention Topic was automatically imported from the old Question2Answer platform.

I have a general “if” condition with a comparative Y position for my enemy node, like:

``````
``````
``````if player.position.y < position.y:
do that
``````

but I was think if it’s possible to make more precise with numerical reference limitation, puting the distance between player position and enemy position with a certain limit; something like:

``````	if player.position.y < 100(position.y):
do that
``````

If it’s possible, how could I write the code? Using clamp?

I’m not sure what you are trying to do… do you mean something like `abs(player.position.y - position.y) < 100`, which means “is the vertical distance between me and the player lower than 100” ?

Zylann | 2019-02-21 21:55

If I understood correctly, you can make this using a range, for example:

``````if player.position.x >50 and player.position.x<100:
velocity+=10
``````

Alex Pires | 2019-02-21 22:06

Zylann:

I was trying to elaborate my question, but I felt a little trouble explaining myself.
You did it better than I could, my question is exactly that.

lucasfazzi | 2019-02-22 00:39

works fine; it is not possible to mark as “best coment”, but Zyllan hit it.

lucasfazzi | 2019-02-22 19:23

I’m not sure what you are trying to do… do you mean something like `abs(player.position.y - position.y) < 100`, which means “is the vertical distance between me and the player lower than 100” ?