Talk:MoveObject

From Multi Theft Auto: Wiki

My Example: Rotate door back

My example of how to move/rotate garage dor back while it's still moving/rotating:

Click to collapse [-]
Server

Wrong:

GarageDoor = 0
GarageChecker = 0

function resourceStart()
  -- LSPD garage door
  GarageDoor = createObject( 3055, 1588.5, -1637.875, 14.6, 0.0, 0.0, 0.0, false )
  GarageChecker = createColSphere( 1588.4886, -1638.1095, 13.4135, 15.0 )
end
addEventHandler( "onResourceStart", getResourceRootElement( getThisResource() ), resourceStart )

function colShapeHit( hitElement, matchingDimension )
  if getElementType( hitElement ) == "vehicle" then
    moveObject( GarageDoor, 2000, 1588.5, -1638.875, 16.5, 85.0, 0.0, 0.0, "Linear", 0.0, 0.0, 0.0 )
  end
end
addEventHandler( "onColShapeHit", GarageChecker, colShapeHit )

function colShapeLeave( hitElement, matchingDimension )
  if getElementType( hitElement ) == "vehicle" then
    moveObject( GarageDoor, 2000, 1588.5, -1637.875, 14.6, 0.0, 0.0, 0.0, "Linear", 0.0, 0.0, 0.0 )
  end
end
addEventHandler( "onColShapeLeave", GarageChecker, colShapeLeave )

Correct:

GarageDoor = 0
GarageChecker = 0

function resourceStart()
  -- LSPD garage door
  GarageDoor = createObject( 3055, 1588.5, -1637.875, 14.6, 0.0, 0.0, 0.0, false )
  GarageChecker = createColSphere( 1588.4886, -1638.1095, 13.4135, 15.0 )
end
addEventHandler( "onResourceStart", getResourceRootElement( getThisResource() ), resourceStart )

function colShapeHit( hitElement, matchingDimension )
  if getElementType( hitElement ) == "vehicle" then
    stopObject( GarageDoor ) -- you must stop object to get it's current rotation angles
    local rX, rY, rZ = getElementRotation( GarageDoor )
    moveObject( GarageDoor, 2000, 1588.5, -1638.875, 16.5, 85.0 - rX, 0.0 - rY, 0.0 - rZ, "Linear", 0.0, 0.0, 0.0 )
  end
end
addEventHandler( "onColShapeHit", GarageChecker, colShapeHit )

function colShapeLeave( hitElement, matchingDimension )
  if getElementType( hitElement ) == "vehicle" then
    stopObject( GarageDoor ) -- you must stop object to get it's current rotation angles
    local rX, rY, rZ = getElementRotation( GarageDoor )
    moveObject( GarageDoor, 2000, 1588.5, -1637.875, 14.6, 0.0 - rX, 0.0 - rY, 0.0 - rZ, "Linear", 0.0, 0.0, 0.0 )
  end
end
addEventHandler( "onColShapeLeave", GarageChecker, colShapeLeave )

-- Leonardo 08:30, 6 September 2013 (UTC)