[SOLVED] applyMovement problems

Hello all,

Im at a loss here.



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 ?

Thanks everone
Dimitris

Try

object.worldPosition = object.worldPosition +object.worldOrientation.col[1]*10

or

from mathutils import Vector
object.worldPosition = object.worldPosition +( object.worldOrientation*Vector([0,10,0])) 

AppllyMovment() is not instant I don’t think.

Thanks, it worked!
(I used the second example, with the Vector ( ) )

your issue is in the [], that means “List” to python. you need to use (), that means tuple to python. you dont need mathutils!

OBJ.applyMovement((X, Y, Z), True) #set to False for world

@Daedalus:
I’m not convinced. I’d be surprised if it treated the tuple differently to the list.

well something didnt work, if its not that, then its the 1 vs the True.

EDIT: i tried the above variants and they all work as expected

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.

You should use tab indent inside a function,


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.

try: “True”, not, “true”. python is case sensitive.

up at the top, by “File”, “Edit,” etc, under “Window” there should be toggle console button.

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.