Captain Cody Posted March 5, 2016 Share Posted March 5, 2016 How would I move an object in front of its self relative to its rotation? Converting an in game object into working ship With WASD controls. But the issue I have is actually getting the ship to move in front of itsself relative to its rotation, any way of doing this? Link to comment
DakiLLa Posted March 5, 2016 Share Posted March 5, 2016 I'd use OOP for that as it has some neat stuff: local myObject = Object.create( ... ) local myOtherObject = Object.create( ... ) local otherObjectOffset = Vector3( 0, 3, 0 ) -- moving 'myOtherObject' on 3 units ahead of 'myObject' over Y axis local otherObjectPosition = myObject.matrix:transformPosition( otherObjectOffset ) myOtherObject:setPosition( otherObjectPosition ) Don't forget to enable OOP in meta.xml. Link to comment
Dealman Posted March 5, 2016 Share Posted March 5, 2016 Worth noting you can achieve the same result without using OOP by using this function; function getPositionFromElementOffset(element,offX,offY,offZ) local m = getElementMatrix ( element ) -- Get the matrix local x = offX * m[1][1] + offY * m[2][1] + offZ * m[3][1] + m[4][1] -- Apply transform local y = offX * m[1][2] + offY * m[2][2] + offZ * m[3][2] + m[4][2] local z = offX * m[1][3] + offY * m[2][3] + offZ * m[3][3] + m[4][3] return x, y, z -- Return the transformed point end -- Get the position of a point 3 units to the right of the element: x,y,z = getPositionFromElementOffset(element,3,0,0) More information can be found looking at getElementMatrix. 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