import bge
cont = bge.logic.getCurrentController()
me = cont.owner
scene = me.scene
emt = scene.addObject("EmptyGeneric", me) #Create an empty where I am
emt.applyMovement([0.0, 10.0, 0.0], 1) # Advance the empty 10 meters forward ( y local axis)
test = scene.addObject("Test", emt) #Create a test object
My problem is that the test object is created “inside” the “me” object.
As if the applyMovement command does nothing.
Perhaps the applyMovement is actually applied next frame ?
I’m actually having a similar issue…I don’t know if it has to do with the dynamic setup for the mesh or what. It is simply setup in the physics tab as dynamic…then an always sensor set to every pulse or whatever…(still a novice here) connected to the script…I’m just(as in the last 10 min :)) starting to pick up the BGE and I cannot get it working…
here is the extremely basic code I setup.
import bge
from mathutils import Vector
def main():
cont = bge.logic.getCurrentController()
player = cont.owner
player.applyMovement((1,0,0), true)
main()
I noted that someone said we do not need mathutils for code, but I read that it was needed for vectors so…there it is…I guess the document I read was wrong.
import bge
from mathutils import Vector
def main():
cont = bge.logic.getCurrentController() #One tab indent, since youare inside the main() function
player = cont.owner #This also
player.applyMovement((1,0,0), true) #This also
#When tab indents end, it means your function ends there
#Here you can define another function etc etc.....
Also, I don’t understand what you mean by the last main() statement.
You do not mention WHY it does not work though, ie what happens when you run it ?
Any error messages ?
mine are properly indented, that was merely a formatting error here on the forums…
*When I start the engine the player moves down until it contacts a surface(typical physics behaviour), aside from that it does nothing. Using the latest stable build right off the blender website (2.78c) also tried it in UPBGE.
as far as error messages go, I am still learning linux and have not figured out how to get the terminal to show them…that in itself would be a big help.
To use the console in linux you have to start blender from a terminal. Generally this is done by opening a terminal and typing ‘blender’ (do quotes) and pressing enter.
Exactly. Learn to do the above, otherwise it is not possible to code a game. Errors do come up even in experienced programmers, from the most dumb reasons (usually for me it is forgotten symbols like " [ ] : etc )
Most likely you have an error in the script (I would guess the last main( ) statement, try removing that). Run from a console and you will know. It tells you what script, what line, what error your have. Post what happened if you can. Good luck.