Jump to content

Move object realtive to the objects rotation


Recommended Posts

Posted

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?

Posted

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.

Posted

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.

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...