i tried but it spit out error I do not understand.
here is the code.
from bge import logic, events
from mathutils import Vector
def PLAYER(cont):
owner = cont.owner
scene = owner.scene
armature = owner.children["Actor.Rig"]
G_VEC(owner)
## Movement ##
kbe = logic.keyboard.events
move = Vector((0,0))
is_gnd = owner.get("IS_GND", "FALSE")
if kbe[events.WKEY] == 2:
move[1] = 1
ACTION(armature, "Running", (0,39), 2, "LOOP", 10)
elif kbe[events.SKEY] == 2:
move[1] = -1
ACTION(armature, "Running", (39,0), 2, "LOOP", 10)
elif is_gnd == "FALSE":
ACTION(armature, "Jumping", (20,20), 2, "LOOP", 10)
else:
ACTION(armature, "Jumping", (0,0), 2, "LOOP", 10)
if kbe[events.AKEY] == 2:
move[0] = -1
elif kbe[events.DKEY] == 2:
move[0] = 1
if kbe[events.SPACEKEY] == 1 and is_gnd == "TRUE":
ACTION(armature, "Jumping", (0,20), 1, "PLAY", 10)
owner.setDamping(0.5, 0.5)
owner.setLinearVelocity((0,0,5), True)
owner["IS_GND"] = "NONE"
move.normalize()
owner.applyMovement((move[0]*0.1,move[1]*0.1,0), True)
def AI(cont):
owner = cont.owner
scene = owner.scene
armature = owner.children["Actor.Rig.001"]
ai = [obj for obj in scene.objects if 'track_to' in obj]
if ai:
closest_ai = sorted(ai, key=lambda enemy: own.getDistanceTo(enemy))[0]
dist, glv, lcv = owner.getVectTo(scene.objects["Player"])
if dist >= 2:
move = (dist-2)*0.1
if move >= 0.1:
move = 0.1
if move > 0.05:
dist = own['track_distance']
elif dist <= max_dist:
ACTION(armature, "Running", (0,39), 2, "LOOP", 10)
elif move > 0.01:
ACTION(armature, "Walking", (0,59), 2, "LOOP", 10)
else:
ACTION(armature, "Jumping", (0,0), 2, "LOOP", 10)
owner.applyMovement((0,move,0), True)
owner.alignAxisToVect(glv, 1, 0.5)
G_VEC(owner)
# Align Objects to Ground
def G_VEC(owner):
zref = owner.get("G_VEC", None)
rayto = owner.children[owner.name+".GroundRay"]
## Align to Gravity (MUST BE FIRST!) ##
if zref != None:
owner.alignAxisToVect(zref, 2, 1.0)
## Ground Stability (MUST BE SECOND!) ##
rayOBJ, rayPNT, rayNRM = owner.rayCast(rayto, None, 1.1, "", 1, 0, 0)
if rayOBJ != None:
if owner.get("IS_GND", "FALSE") != "NONE":
owner["IS_GND"] = "TRUE"
owner.setDamping(1.0, 1.0)
owner.applyForce((zref*9.8*owner.mass), False)
owner.worldPosition = rayPNT+(zref*1)
else:
owner.setDamping(0.5, 0.5)
owner["IS_GND"] = "FALSE"
# Play Action
def ACTION(OBJECT, NAME=None, FRAME=(0,0), PRIORITY=0, MODE="PLAY", BLEND=0, STOP=False):
if STOP == True:
OBJECT.stopAction(LAYER)
return
if NAME == None:
NAME = OBJECT.name
LAYER = 0
SPEED = 1
LYRWGHT = 0
IPO_FLG = 0
if MODE == "PLAY":
PLAYTYPE = logic.KX_ACTION_MODE_PLAY
elif MODE == "LOOP":
PLAYTYPE = logic.KX_ACTION_MODE_LOOP
BLENDTYPE = logic.KX_ACTION_BLEND_BLEND
OBJECT.playAction(NAME, FRAME[0], FRAME[1], LAYER, PRIORITY, BLEND, PLAYTYPE, LYRWGHT, IPO_FLG, SPEED, BLENDTYPE)