Jump to content

Перемещение объекта мышкой + клавиатурой


Recommended Posts

Всем привет.

Как сделать, чтобы объект можно было вращать и перемещать с использованием курсора мыши и клавиш на клавиатуре.

function updatePos() 
    local object = tempOb[localPlayer] 
    if object then 
        guiSetVisible(baseCPanel.window[1], false) 
        local screenX, screenY = guiGetScreenSize() 
        local x,y = getCursorPosition() 
        local x,y = x*screenX,y*screenY 
        local sX,sY,sZ = getWorldFromScreenPosition(x,y,0) 
        local sX2,sY2,sZ2 = getWorldFromScreenPosition(x,y,20) 
        local hit,oX,oY,oZ = processLineOfSight(sX,sY,sZ,sX2,sY2,sZ2,true,false,false,true,false,true,false,false,object) 
        if not hit then return end 
        setElementPosition(object,oX,oY,oZ + getElementDistanceFromCentreOfMassToBaseOfModel(object)) 
    end 
end 

local rotationAxis = "z" 
function setRotationOfObject(button,state) 
    local object = tempOb[localPlayer] 
    if button == "arrow_u" or button == "arrow_d" then 
        if state then 
            rotationAxis="y" 
        else 
            rotationAxis="z" 
        end 
    elseif button == "arrow_r" or button == "arrow_l" then 
        if state then 
            rotationAxis="x" 
        else 
            rotationAxis="z" 
        end 
    end 
    if not state then return end 
    if button == "mouse_wheel_up" or button == "pgup" then 
        if rotationAxis == "z" then 
            local x,y,z = getElementRotation(object) 
            setElementRotation(object,x,y,z+5) 
        elseif rotationAxis == "y" then 
            local x,y,z = getElementRotation(object) 
            setElementRotation(object,x,y+5,z) 
        elseif rotationAxis == "x" then 
            local x,y,z = getElementRotation(object) 
            setElementRotation(object,x+5,y,z) 
        end 
    elseif button == "mouse_wheel_down" or button == "pgdn" then 
        if rotationAxis == "z" then 
            local x,y,z = getElementRotation(object) 
            setElementRotation(object,x,y,z-5)   
        elseif rotationAxis == "y" then 
            local x,y,z = getElementRotation(object) 
            setElementRotation(object,x,y-5,z) 
        elseif rotationAxis == "x" then 
            local x,y,z = getElementRotation(object) 
            setElementRotation(object,x-5,y,z) 
        end  
    end 
end 

Если я добавлю примерно такой код:

    elseif button == "num_2" then 
            local x,y,z = getElementPosition(object) 
            setElementPosition(object,x,y,z+1) 
  

То появляется вот такая проблема: когда я жму num2, объект поднимается вверх, но так как в этом месте стоит курсор, объект принимает позицию курсора. Как это можно исправить?

Вот видео:

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