Jump to content

[Help] Positions regarding Directions.


Swagy

Recommended Posts

  • Discord Moderators

If your object is not axis-aligned, that is if it points in a different direction than the X/Y/Z axis, then you need to pull up a calculator to find the forwards position, because your object will be moving in multiple axes

The easiest way is to use a transform matrix. Take a look here and see the examples. Let me know if you need more explanation.

Link to comment

Oh right thanks alot Zango,

Is this what am I looking for tho ?

function getMatrixLeft(m)
    return m[1][1], m[1][2], m[1][3]
end
function getMatrixForward(m)
    return m[2][1], m[2][2], m[2][3]
end
function getMatrixUp(m)
    return m[3][1], m[3][2], m[3][3]
end
function getMatrixPosition(m)
    return m[4][1], m[4][2], m[4][3]
end

local mat = getElementMatrix(element)  -- Get the matrix
x,y,z = getMatrixLeft(mat)     -- Get the matrix left direction
x,y,z = getMatrixForward(mat)  -- Get the matrix forward direction
x,y,z = getMatrixUp(mat)       -- Get the matrix up direction

 

Link to comment
  • Discord Moderators

Yes that will work. In your case you want to find the forwards position

function getMatrixForward(m)
    return m[2][1], m[2][2], m[2][3]
end

local mat = getElementMatrix(element)  -- Get the matrix
local x, y, z = getMatrixForward(mat)  -- Get the matrix forward direction

local offset = 1 -- Our offset length, how far forwards you want the object

-- Get our transformed point by multiplying the offset
x = x * offset
y = y * offset
z = z * offset

-- Add these values to the element position
-- mat[4] contains position coordinates
x = x + mat[4][1]
y = y + mat[4][2]
z = z + mat[4][3]

 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...