Here is an example of my player movement/Click to walk script on my player
import bge
from bge import logic
from bge import events
cont = logic.getCurrentController()
key = logic.keyboard.events
obj = cont.owner
moveto = cont.actuators["moveto"]
track = cont.actuators["track"]
movetrack = cont.actuators["movetrack"]
near = cont.sensors["near"]
#####PLAYER MOVEMENT AND WALKING####
###SPEEDS FOR VERTICAL AND DIAGNOLS###
xx = .050 #vert horz
xy = .035 #diag
rs = .055 #rotate speed
##UP##
if key[bge.events.WKEY]==2 and not key[bge.events.AKEY]==2 and not key[bge.events.DKEY]==2:
obj.applyMovement([0,xx,0],1)
cont.deactivate(moveto)
cont.deactivate(track)
cont.activate(movetrack)
##UPLEFT##
if key[bge.events.WKEY]==2 and key[bge.events.AKEY]==2:
obj.applyMovement([-xy,xy,0],1)
cont.deactivate(moveto)
cont.deactivate(track)
cont.activate(movetrack)
##UPRIGHT##
if key[bge.events.WKEY]==2 and key[bge.events.DKEY]==2:
obj.applyMovement([xy,xy,0],1)
cont.deactivate(moveto)
cont.deactivate(track)
cont.activate(movetrack)
##STRAFELEFT
if key[bge.events.AKEY]==2 and not key[bge.events.WKEY]==2 and not key[bge.events.SKEY]==2:
obj.applyMovement([-xx,0,0],1)
cont.deactivate(moveto)
cont.deactivate(track)
cont.activate(movetrack)
##STRAFERIGHT
if key[bge.events.DKEY]==2 and not key[bge.events.WKEY]==2 and not key[bge.events.SKEY]==2:
obj.applyMovement([xx,0,0],1)
cont.deactivate(moveto)
cont.deactivate(track)
cont.activate(movetrack)
##DOWN##
if key[bge.events.SKEY]==2 and not key[bge.events.AKEY]==2 and not key[bge.events.DKEY]==2:
obj.applyMovement([0,-xx,0],1)
cont.deactivate(moveto)
cont.deactivate(track)
cont.activate(movetrack)
##DOWNLEFT##
if key[bge.events.SKEY]==2 and key[bge.events.AKEY]==2:
obj.applyMovement([-xy,-xy,0],1)
cont.deactivate(moveto)
cont.deactivate(track)
cont.activate(movetrack)
##DOWNRIGHT##
if key[bge.events.SKEY]==2 and key[bge.events.DKEY]==2:
obj.applyMovement([xy,-xy,0],1)
cont.deactivate(moveto)
cont.deactivate(track)
cont.activate(movetrack)
##ROTATION HERE###
if key[bge.events.QKEY]==2:
cont.deactivate(movetrack)
cont.deactivate(track)
obj.applyRotation([0, 0,rs],1)
if key[bge.events.EKEY]==2:
cont.deactivate(movetrack)
cont.deactivate(track)
obj.applyRotation([0, 0,-rs],1)
#####ACTIVATES WALKING TO POINTER
if logic.globalDict["clickwalk"] == True:
cont.activate(track)
cont.activate(moveto)
###DEACTIVATES IF NEAR SENSOR IS POSITIVE
if near.positive:
cont.deactivate(moveto)
logic.globalDict["clickwalk"] = False
cont.deactivate(movetrack)
as you can see its all basically:
if this
___do this
When im looking through scripts such as one of the most popluar mouselook scripts they have lines like this
Def(something)
_____thisthis
For some reason this scripts are hard to understand becase i dont really know what the Def()'s do. I know they run but I dont know how. When I try to pick apart the scripts theyll stop working. Today I was thinking about my above script and thought maybe def worked like this.
Instead of having all the end tracking/moving actuators per each movment key press in the script. Maybe Def() worked like this:
def(deactivate)
_____controller.deactivate.(moveto), controller.deactivate.(trackto)
and then put
if walk key
___(deactivate)
am i starting to understand or am I way off. Is there a simple example of a script with Def(that I can understand)? I just want to know how to use it if i Will need to know it, because alot of example scripts use Def()