Mouse Sliders in UPBGE_0.2.5 and UPBGE_0.3.0

slider_guts_finished.blend (517.9 KB)

slider_guts_finished_2_8.blend (688.3 KB)

import bge
from mathutils import Vector
import mathutils


def main():

    cont = bge.logic.getCurrentController()
    own = cont.owner
    MO = cont.sensors['MouseOver']
    Click = cont.sensors['Click']
    if 'engaged' not in own:
        if MO.positive and Click.positive:
    
            #begin using a slider
            own['engaged']=MO.hitObject
            bge.render.showMouse(False)
            bge.render.setMousePosition(int(bge.render.getWindowWidth() / 2), int(bge.render.getWindowHeight() / 2))
            
            
            #print('fire')
        
    else:
        #finished sliding
        if not Click.positive:
            bge.render.showMouse(True)
            if 'engaged' in own:
                del own['engaged']
                
        
        #sliding        
        else:
            c = Vector( [bge.render.getWindowWidth() / 2, bge.render.getWindowHeight()/2])
            diff = Vector(MO.position)-c
            #print(diff)
            if abs(diff[0])>2:
                p1 = own['engaged'].parent.worldTransform * Vector([-0,-3,0])
                p2 = own['engaged'].parent.worldTransform * Vector([0,3,0])    
                own['engaged'].applyMovement([0,diff[0]*.01,0])
                local = own['engaged'].parent.worldTransform.inverted() * own['engaged'].worldPosition
                if local.y<-3:
                    own['engaged'].worldPosition = p1
                if local.y>3:
                    own['engaged'].worldPosition = p2
                
                bge.render.setMousePosition(int(bge.render.getWindowWidth() / 2), int(bge.render.getWindowHeight() / 2))
                p3 = own['engaged'].worldPosition 
                PL =  mathutils.geometry.intersect_point_line(p3, p1, p2)
                
                
                own['engaged']['var'] =own['engaged']['Offset']+  (PL[1]*own['engaged']['Scale'])
            

main()
4 Likes

Cool. :blue_heart:
I will use that to modify shaders in-game.

1 Like

Cool. Thank You. Downloadet to my Demo Archive.

1 Like