+1 vote

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?

in Engine by (170 points)

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" ?

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

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.

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

I copied it as answer.

1 Answer

+1 vote
Best answer

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" ?

by (28,740 points)
selected by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.