Community Forum

How do I get the proper world location of objects ingame?

Forum Overview >> Farming Simulator 17

CategoryFarming Simulator 17
Created09.03.2017 22:07

Tim Derks (timmiej93) 09.03.2017 22:08
For a mod I'm working on, I need to get the distance between two objects. To achieve this, I call getWorldTranslation() on both, and then calculate the distance with the differences between the X and Z coordinates. When I checked in the Giants editor, the difference in X was 12, and the difference in Z was 0 (two map objects, obtained coordinates by calling getWorldTranslation() in the editor on the respective Ids). When I get the delta of the coordinates obtained by getWorldTranslation() in game, I get 3.5, a very different distance. Is this caused by a difference in coordinate spacing in game vs. in the editor? Am I doing something wrong? What on earth is going on here?

For reference, this code calculates the distance between coordinates:
local x1, y1, z1 = getWorldTranslation(point1)
local x2, y2, z2 = getWorldTranslation(point2)
local dx, dz = math.abs(x1-x2), math.abs(z1-z2)

Bilbo Beutlin (BBeutlin) 10.03.2017 13:44
FS acts in a 3-dimensional world. You need all three components of the vectors.
local x1,y1,z1 = getWorldTranslation(object1);
local x2,y2,z2 = getWorldTranslation(object2);
local distance = Utils.vector3Length(x2-x1,y2-y1,z2-z1);

Tim Derks (timmiej93) 10.03.2017 22:20
You are technically correct, but I'm not at all interested in the Y difference, so deltaX and deltaZ will suffice for my goal. With a lot of testing, I think I figured out that false object ids were the cause of this error.

Note: Log in to post. Create a new account here.