Jump to content

Moving Items


Slimwaffle
 Share

Recommended Posts

I am so happy I got this working I am going to share it with you guys. These scripts will allow you to move items around in game. Enjoy :D

The first script is here;

--Generic Item Script
function Script:Start()
    self.entity:SetKeyValue("type","item")
    pos = self.entity:GetPosition()

end

function Script:UpdateWorld()

end

Now the Second Script to actually move the item;

--Script to move Item

Script.camPick = false
Script.radius = 1

function Script:Start()
    self.player = self.entity:GetParent()
    self.camera = self.player.script.camera
    
end

function Script:UpdateWorld()
    local pickInfo = PickInfo()
    local mouse = window:GetMousePosition()

    if self.camera:Pick(mouse.x, mouse.y, pickInfo, self.radius, true,2) then
        if pickInfo.entity:GetKeyValue("type") == "item" then
            self.camPick = true
        end
    else
        self.camPick = false
    end
    local pickInfo = PickInfo()
    local mouse = window:GetMousePosition()
    if self.camera:Pick(mouse.x, mouse.y, pickInfo, self.radius, true,2) then
        pickInfo.entity:SetPickMode(Entity.PolygonPick)
        dist = self.camera:GetDistance(pickInfo.entity,false)
        if dist >= 20 then 
            self.camPick = false
        end
        
        if self.camPick == true then
            if pickInfo.entity:GetKeyValue("type") == "item" then
                if window:KeyDown(Key.Q) then
                  --UnProject mouse coordinates from screen space to world space and position the box there
                    local p = window:GetMousePosition()
                    p.z = 3 --distance in front of the camera to project to
                    p = self.camera:UnProject(p)
                pickInfo.entity:SetPosition(p)
                
                end
            end
        end
    end

end

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...