Vector.get_distance()

Please post any questions about developing your plugin here. Please use the search function before posting!
decompile
Senior Member
Posts: 416
Joined: Sat Oct 10, 2015 10:37 am
Location: Germany
Contact:

Vector.get_distance()

Postby decompile » Tue Jul 26, 2016 7:44 pm

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
User avatar
Ayuto
Project Leader
Posts: 2195
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Re: Vector.get_distance()

Postby Ayuto » Tue Jul 26, 2016 8:03 pm

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))
decompile
Senior Member
Posts: 416
Joined: Sat Oct 10, 2015 10:37 am
Location: Germany
Contact:

Re: Vector.get_distance()

Postby decompile » Tue Jul 26, 2016 9:42 pm

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.
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: Vector.get_distance()

Postby L'In20Cible » Wed Jul 27, 2016 4:10 am

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.

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 131 guests