I tried to write a script that is able to do all what the “Movement sensor” does but to no success.
Please if you can do it, a help from you will be appreciated.
Thanks
I got the problem too , I fail when I try to test the code from official document to move actor via python script, and then I try to do ‘import bge’ in blender scriping console, it tell me no moulde name bge.
need help too.
UPBGE 0.3+ ships with a Python Component script template for mouse look:
You can also use the Mouse Look logic node if you don’t wish to use Python or Logic Bricks:
Ain’t talking about mouse sensor dude
Ahh, my mistake.
There’s no “native” module to my knowledge for joystick movement functions, but there the Python-side of the Movement sensor available. You’ll still need a Movement sensor for the Python code to work though.
Documentation:
https://upbge.org/#/documentation/docs/latest/api/bpy.types.MovementSensor.html
Thanks for trying.
But i still don’t know how to use it in script/code form
What exactly are you trying to accomplish with code for your joystick?
I want to be able to check if an object has moved in a given axis and then play an animation. The animation is different according to the axis the object moved
Ahh… I seem to have again misunderstood your post. You can check if and which movement an object is moving towards by checking its linear velocity:
import bge
def main(self):
print(self.owner.linearVelocity)
This will print all 3 location axis’s (Location, Rotation, Scale).
You can also restrict the checking of an individual axis, e.g. Check for the x-axis only.
Check a individual axis using a function method
import bge
def main(self):
print(self.owner.linearVelocity.x)
Check a individual axis using a list index
import bge
def main(self):
print(self.owner.linearVelocity[0])
Thank you😊
import bge
cont = bge.logic.getCurrentController()
own =cont.owner
if 'x' not in own:
own['x'] = own.worldPosition.x
else:
diff = abs(own.worldPosition.x)
if diff > min_move:
own["moving"] = 15
own['x'] = own.worldPosition.x
Whats min_move
You define it,
The smallest amount of movement that will trigger it
There is a problem. The code works fine only if the object physics isn’t “Character” but my object has “Character” physics.
Then use the KX_CharacterWrapper function walkDirection instead:
import bge
VAR_SPEED = 0.5
def main(self):
print(bge.constraints.getCharacter(self.owner).walkDirection)
bge.constraints.getCharacter(self.owner).walkDirection = [0,0,0]
if bge.logic.keyboard.inputs[bge.events.WKEY].active:
bge.constraints.getCharacter(self.owner).walkDirection = [0,VAR_SPEED,0]
if bge.logic.keyboard.inputs[bge.events.SKEY].active:
bge.constraints.getCharacter(self.owner).walkDirection = [0,-VAR_SPEED,0]
if bge.logic.keyboard.inputs[bge.events.AKEY].active:
bge.constraints.getCharacter(self.owner).walkDirection = [-VAR_SPEED,0,0]
if bge.logic.keyboard.inputs[bge.events.DKEY].active:
bge.constraints.getCharacter(self.owner).walkDirection = [VAR_SPEED,0,0]
It seems even good old Monster didn’t realize this you could use that function that particular way: