0 votes


Comparing two vectors with the same coordinates returns false.

Waypoint is a vector 3 in this scenario.

self.get_translation() == waypoint

returns false although this these are the coordinates given by the output:

(1.05922, 12.412035, -0.650758) < waypoint
(1.05922, 12.412035, -0.650758) < self.get_translation()

Then i tried to check the state via the distance and tried

var distance = self.get_translation().distance_to(waypoint) == 0
distance == 0.0

Same problem.

print distance 

shows 0

But now comes the funny part. Both parts work at the beginning. They return true when they should.

But after a while (reproducable at the same time) they return false.

Thanks for your time!

in Engine by (15 points)
edited by

1 Answer

+2 votes
Best answer

Because of floating point errors, two floats could look similar but have a very small difference.

Instead of If Vector == Vector try if Vector > Vector
This also solves other floating point errors like 1/3.

by (1,451 points)
selected by

Thanks for the tip! I'm now working with the distance and an adjustable tolerance value. Everything works fine now!

if abs(self.get_translation().distance_to(waypoint)) < tolerance
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.