Move object with keys¶
move.py¶
1# © 2024 Autodesk, Inc. All rights reserved.
2
3print("Executing move script!")
4
5newScene()
6
7def moveLeft(node, step):
8 pos = node.getTranslation()
9 node.setTranslation(pos[0] - step, pos[1], pos[2])
10
11def moveRight(node, step):
12 pos = node.getTranslation()
13 node.setTranslation(pos[0] + step, pos[1], pos[2])
14
15def moveUp(node, step):
16 pos = node.getTranslation()
17 node.setTranslation(pos[0], pos[1] + step, pos[2])
18
19def moveDown(node, step):
20 pos = node.getTranslation()
21 node.setTranslation(pos[0], pos[1] - step, pos[2])
22
23loadGeometry("$VRED_EXAMPLES/geo/cube.osb")
24updateScene()
25
26# Searches for the node via regular expression.
27cube = findNode("*cube*", true);
28cube.makeTransform()
29
30# move speed
31step = 100
32
33keyA = vrKey(Key_A)
34keyA.connect(moveLeft, cube, step)
35
36keyD = vrKey(Key_D)
37keyD.connect(moveRight, cube, step)
38
39keyW = vrKey(Key_W)
40keyW.connect(moveUp, cube, step)
41
42keyS = vrKey(Key_S)
43keyS.connect(moveDown, cube, step)
44
45vrLogWarning("Press key W, A, S, D to move the object.")