I want to make my spaceship/plane fly by the arrow keys. My basic idea was:
keys = [arrow-up,arrow-down,arrow-left,arrow-right,arrow-up-up,arrow-down-down,arrow-left-left,arrow-right-right]
keysp = check_for_key(string(keys))
actions = [FLY_UP, FLY_DOWN, TURN_RIGHT, TURN_LEFT, LEAN_RIGHT, LEAN_LEFT]
if keysp = arrow-x:
action = "FLY_x"/"TURN_x/"LEAN_x"
action = ""
if action = "FLY_x"/"TURN_x/"LEAN_x":
But it did not work. Btw I am actually too unfamiliar with FMS/.gametask so I did not use it better. IMO it’s too sophisticated.
your code sorta is a bit of a “guessed together thing”.
first of you need to make sure to know how to capture and use keyboard inputputs/events. several examples in the panda installation are demonstrating this. like the roaming ralph, the asteroid , but also many others where keys are used to simply switch light on/off etc.
once you got those events. you can change your movement-variables like.
once you changed those you need to update the spaceships position inside a task which runs once per frame where you basically do something as simple as: spaceshipt.setY(spaceshipt , passedTimeSinceLastFrame*speed)
i recommend looking at the roaming ralph or asteroids example. or other examples on the forum. most involve movement in some way. (the movement code itself in roaming ralph is a bit overhead but well it works,too.)
btw. i think this has been discussed many times on the forum already.
*critism(don’t read if you find Panda uber-mega cool):
[size=59]the problem of Panda’s sample games/overall Panda’s syntaxes is that are they IMO too complex. Why not just:[/size]
a = accept.keys([arrows,S];[FLY_UP,FLY_DOWN,TURN_RIGHT,TURN_LEFT])
if a = :
b = x
[size=59]like 60% of other good engines do?
But I will better study roaming ralph
the reasons are simple.
it would break the python syntax,
it would force a number of limitations onto the developer,
it would not work;)
well actually it works really close to how you want it to. all you need to do is to add some basic math, and the correct python code.
please notice: the roaming ralph code is not a good example of how to do movement.it involved a lot of unnecessary code and messing with matrices and the like. it was reworked and will be updated in the next panda-release. for now consider to check other examples in the codesnippset/showcase section of the forum.
[EDIT] ah. i was lacking behind releases a bit. it’s already updated in 1.6.0 .
moving ralph itself is done around line 188.