I have created a simple maze with a cone that moves throughout. Right now I am using W:move forward, A:rotate left, S:move backward, and D:rotate right. What I would like to do is have the ‘face’ of the cone track the mouse and use ‘WASD’ for movement only (no rotation). In other words, you would ‘strafe’ around the mouse. This control scheme would be similar to what you would expect from a 3rd-person shooter. It is my understanding that this cannot be done in the GUI and requires a python script. I’ve been trying to get it to work by modifying different examples that sound similar but have had no luck (many examples seem to be using deprecated objects and methods).
I would greatly appreciate some help on this issue, either in the form of snippets of example code or a reference to a working article. After many revisions I’m pretty much back to square one:
print("start") cont = GameLogic.getCurrentController()#store controller as 'cont' player = cont.owner#store object as 'player' mouse = cont.sensors["mouseTest_S"]#store sensor as 'mouse' #rotX= cont.actuators["mouseTest_AX"]#store actuator as 'rotX' #rotY= cont.actuators["mouseTest_AY"]#store actuator as 'rotY' print(mouse.position,mouse.position)#print x,y of mouse print(cont)#print controller "mouseTest_C" print(cont.sensors)#print sensor print(cont.actuators)#print actuator print(player.position)#prints player position # Get the actuators posX = cont.actuators["rotX"] posY = cont.actuators["rotY"] #???somehow rotate 'player' object with actuators so face is always pointed toward mouse.position,mouse.position??? print("end")
Sorry if this question has been asked before; I couldn’t find a similar post elsewhere or working instructions. This is my first time doing any movement at all, so I apologize if I’m missing something simple. Thanks in advance!
tmp=mouse.position lClick = cont.sensors["mouseTest_S"] if lClick.positive: print("clicked") player.position = [tmp/100,0,tmp/100]
makes it so that my cone will shoot to the clicked spot, and its wildly inaccurate. I think this is a step in the right direction but I’d like it to just look at my mouse though… and use the same scale (not sure why mouse position has such higher numbers–hundreds instead of tens).