Swagy Posted April 27, 2020 Share Posted April 27, 2020 So hello guys, I want to know which axis controls the movement in directions. For example: I want to move an obejct forwards, how to check which axis to modify to move the object forwards ? Link to comment
Discord Moderators Zango Posted April 28, 2020 Discord Moderators Share Posted April 28, 2020 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
Swagy Posted April 28, 2020 Author Share Posted April 28, 2020 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 Zango Posted April 29, 2020 Discord Moderators Share Posted April 29, 2020 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
Swagy Posted April 29, 2020 Author Share Posted April 29, 2020 Thanks a million @Zango Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now