Page 1 of 1

Vector.get_distance()

Posted: Tue Jul 26, 2016 7:44 pm
by decompile
Im having some weird issues,

Syntax: Select all

player_loc = player.location
print("Test | PlayerLoc: %s" % player_loc)
grid_loc = GetGridPosition(player_loc)
print("Test | GridLoc: %s" % grid_loc)
print(Vector.get_distance(player_loc, grid_loc))


Code: Select all

Test | PlayerLoc: Vector(193.81419372558594, 3332.374267578125, 8.03125)
Test | GridLoc: Vector(192.0, 3328.0, 8.0)
0.0


Why is it always returning 0.0

Re: Vector.get_distance()

Posted: Tue Jul 26, 2016 8:03 pm
by Ayuto
Not that it should matter, but the intended way of using a method looks like this:

Syntax: Select all

print(player_loc.get_distance(grid_loc))

I'm not able to reproduce this issue with this test code:

Syntax: Select all

from mathlib import Vector

vec1 = Vector(193.81419372558594, 3332.374267578125, 8.03125)
vec2 = Vector(192.0, 3328.0, 8.0)

print(vec1.get_distance(vec2))

Re: Vector.get_distance()

Posted: Tue Jul 26, 2016 9:42 pm
by decompile
Dunno why but it works now by recreating the Vector.

I was using a copy of player_loc and modify all its values inside (to the grid 64) and returned the same Vector but modified back. After creating a new Vector instance and inserting the modified values it finally gives me the right distance.

Re: Vector.get_distance()

Posted: Wed Jul 27, 2016 4:10 am
by L'In20Cible
decompile wrote:Dunno why but it works now by recreating the Vector.

I was using a copy of player_loc and modify all its values inside (to the grid 64) and returned the same Vector but modified back. After creating a new Vector instance and inserting the modified values it finally gives me the right distance.

That is normal. If you modify an object which point to the same wrapped Vector instance as another, both are modified (since like mentionned, they both points to the same instance therefore the same address).

This would have been easilly explained if you had shared the entire code.