Hello
I'm wanting to trigger a material switch using the HTC Vive motion controllers.
Currently, I have a basic sphere set up which shares a touch sensor and switch material cycle with the vehicle I'm working on. I can manually change them upon a mouse click in real time, which is good - but how would I implement say, a button press, or collision event so when the motion controller is in the sphere, it can cycle through the materials?
I have no knowledge of Python, and am willing to learn - if there's anywhere anyone can point me to get to grips with it, that'd be awesome!
Thanks
Solved! Go to Solution.
Hello,
You just need to create a Touch Sensor on your node ( Interaction > Touch Sensor), with a variant set wich will change your material, then when you'll click with your controller on the node, your material will change. (for example)
Hello
Thanks for your reply!
I have that set up with the relevant code, and I can change material with a trigger press, for example:
def trigger1Pressed():
controller1.setPickingAxis(1)
controller1.showPickingAxis(true)
print "Trigger 1 Pressed"
def trigger1Released():
pickedNode = controller1.pickNode()
selectNode(pickedNode)
triggerTouchSensor("r8_gt_mb:r8_gt_obj:r8_gt_body_TouchSensor")
controller1.showPickingAxis(false)
print "Trigger 1 Released"
However, the material changes no matter where I'm aiming, is there a way to stop this happening? And Only have it change when you're aiming at the object?
Sorry if this is all very simple, I am very new to both Python and VRED!
Thanks again
You should try this :
- Put this function in your script
def triggerSensor( node): if node.hasAttachment("TouchSensorAttachment"): touchAttachment = node.getAttachment("TouchSensorAttachment") acc = vrFieldAccess(touchAttachment) if acc.isValid(): variantSetName = acc.getMString("variantSets") for vset in variantSetName: selectVariantSet(vset) controller1.triggerHapticPulse(0,1000) return parentNode = node.getParent() if parentNode.isValid(): triggerSensor( parentNode)
- Then, just keep that in your Triggers functions :
def trigger1Pressed(): controller1.setPickingAxis(0) controller1.showPickingAxis(true) def trigger1Released(): pickedNode = controller1.pickNode() controller1.showPickingAxis(false) triggerSensor(pickedNode)
With that, if you have a touchsensor attached to a node, when you'll aim it and click it, it should work...
Hello!
Thanks for your reply!!
That has solved my issue, really appreciate the help!!
All the best
Harry
Can't find what you're looking for? Ask the community or share your knowledge.