Jump to content

Objetos 3D Movidos Pelo Cursor.


Recommended Posts

É Possível utilizar posições do seu mouse para mover objetos ?, testei uns exemplos do próprio fórum mais não está retornando as posições corretas.

 

Obj = {}

function teste()
    if Obj[localPlayer] and isElement(Obj[localPlayer]) then
        destroyElement(Obj[localPlayer])
        Obj[localPlayer] = nil
    end
    Obj[localPlayer] = createObject(964, 656.042, -1120.322, 48.605)
end
addCommandHandler("teste2",teste)

addEventHandler( "onClientRender", getRootElement( ),
function ()
    if isCursorShowing() and Obj[localPlayer] and isElement(Obj[localPlayer]) then
        local sx, sy = guiGetScreenSize()
        local relX, relY = getCursorPosition()
        local cursorX, cursorY = relX * sx, relY * sy
        local camX, camY, camZ = getCameraMatrix()
        local cursorWorldPosX, cursorWorldPosY, cursorWorldPosZ = getWorldFromScreenPosition(cursorX, cursorY, 1000)
        local z = getGroundPosition(Vector3(getElementPosition(localPlayer)))
        setElementPosition(Obj[localPlayer], cursorWorldPosX, cursorWorldPosY, z)
    end
end
)

 

Link to comment
18 hours ago, LucasST said:

É Possível utilizar posições do seu mouse para mover objetos ?, testei uns exemplos do próprio fórum mais não está retornando as posições corretas.

 



Obj = {}

function teste()
    if Obj[localPlayer] and isElement(Obj[localPlayer]) then
        destroyElement(Obj[localPlayer])
        Obj[localPlayer] = nil
    end
    Obj[localPlayer] = createObject(964, 656.042, -1120.322, 48.605)
end
addCommandHandler("teste2",teste)

addEventHandler( "onClientRender", getRootElement( ),
function ()
    if isCursorShowing() and Obj[localPlayer] and isElement(Obj[localPlayer]) then
        local sx, sy = guiGetScreenSize()
        local relX, relY = getCursorPosition()
        local cursorX, cursorY = relX * sx, relY * sy
        local camX, camY, camZ = getCameraMatrix()
        local cursorWorldPosX, cursorWorldPosY, cursorWorldPosZ = getWorldFromScreenPosition(cursorX, cursorY, 1000)
        local z = getGroundPosition(Vector3(getElementPosition(localPlayer)))
        setElementPosition(Obj[localPlayer], cursorWorldPosX, cursorWorldPosY, z)
    end
end
)

 

Tá 1000 de distancia no getWorldFromScreenPosition, talvez esteja funcionando mas o item está indo parar lá na puta que pariu e vc n tá conseguindo ver. Está aparecendo algum erro no debugscript?

Edited by Boechat
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...