Topic: This Clicking Script isn't working(solved)

I can't figure out why this code isn't working. The object does have physics enabled, and the "unprojected" object is in the game.

Unprojected = getObject("Unprojected")
clicked = false

function Click(objectName,camera)
    --[[----------------------------------------------------------------------UNPROJECTED POINT]]
    mx = getAxis("MOUSE_X")
    my = getAxis("MOUSE_Y")    

    V1 = getUnProjectedPoint(camera, vec3(mx, my, 0))
    V2 = getUnProjectedPoint(camera, vec3(mx, my, 4))

    point, Unprojected = rayHit(V1, V2) -- note that rayHit only detects objects with physics enabled
    
    
    if point then --if there is a collision between camera and a point (x,y,z) where x is mouse position, and y is mouse position and z is extended in front...
        Xname = getName(Unprojected)
        Xobj = getObject(Xname)
        --setText(text,Xname)
        --print(Xname)
        
        if Xname == objectName and onKeyDown("MOUSE_BUTTON1") then 
            deactivate(Xobj) 
            playSound(sound) 
            clicked = true 
        --[[else 
            clicked = false --]]
        end
    end
        
end    

function onSceneUpdate()
    Click("monkey",mainCamera)
end

Last edited by Tutorial Doctor (2014-04-28 16:02:25)

Re: This Clicking Script isn't working(solved)

I figured out how to change the code for it to work!

Unprojected = getObject("Unprojected")
clicked = false

function Click(objectName,camera)
    --[[----------------------------------------------------------------------UNPROJECTED POINT]]
    mx = getAxis("MOUSE_X")
    my = getAxis("MOUSE_Y")    

    V1 = getUnProjectedPoint(camera, vec3(mx, my, 0))
    V2 = getUnProjectedPoint(camera, vec3(mx, my, 1))

    --point, Unprojected = rayHit(V1, V2) -- note that rayHit only detects objects with physics enabled
    
    point = rayHit(V1,V2,objectName)
    
    
    if point then --if there is a collision between camera and a point (x,y,z) where x is mouse position, and y is mouse position and z is extended in front...
        Xname = getName(objectName)
        Xobj = getObject(Xname)
        --setText(text,Xname)
        --print(Xname)
        
        if Xname == getName(objectName) and onKeyDown("MOUSE_BUTTON1") then 
            --deactivate(Xobj)
            deactivate(Xobj)            
            playSound(sound) 
            clicked = true 
        --[[else 
            clicked = false --]]
        end
    end
        
end    

Last edited by Tutorial Doctor (2014-04-28 16:03:22)