I'm quite new at Blender (and Python) and I have had some problems with a project I'm doing. Right now I'm having a little problem with two methods: aignAxisToVect and applyRotation.

I don't know why, but every time I swap between the Python controller's mode (module and script) one of the two methods works and the other doesn't.

Here I left a link with the blend file, I commented the part that generate the problem within PlanetaryGravity.py.

To further describe the situation: I have a planet with its own orbit (and the World's gravity set to 0) and an object (Cube) that is attracted by the artificial gravity force of the planet. The Cube has a Camera parented to it and I can rotate the camera up/down/left/right with the mouse. The keys W, S, A, D are used to move the Cube over the Planet.

Now, when I use a main() function to configure the Planet's gravity (within PlanetaryGravity.py ), I can rotate the Camera and the Cube with the mouse and move the Cube with the keys, but the Cube doesn't get align to the perpendicular vector to the Planet (so the local axis of the Cube don't change and it's not correctly positioned onto the Planet's surface).

On the other hand, when I delete the main() function and use the script mode for the Python controller, the Cube's axis does get aligned correctly, but I can't rotate the Cube with the mouse (not the camera).

At the end it looks like the method aignAxisToVect overwrites the changes made by the method applyRotation when trying to rotate the Cube with the mouse. So how can I get both the axis alignment and Cube rotation to work? Additionally, why doesn't aignAxisToVect work while Python controller mode is set to Module:PlanetaryGravity.main?


2 Answers 2


At the end it looks like the method aignAxisToVect overwrites the changes made by the method applyRotation

That should be correct, alignAxisToVect should be instantaneous and complete and can overwrite whatever rotation you have applied with the mouse. So you probably just want to change the order of execution.



codefrom bge import logic

#Obter controlador, cena atual e objeto ao qual está executando o script

codecont = logic.getCurrentController()
codescene = logic.getCurrentScene()
codeown = cont.owner

#Obtém o objeto 'Planetary' da cena atual

codeplanetary = scene.objects['Planetary']

#Obtém o vetor da variável referente ao objeto 'Planetary'

codevetor = own.getVectTo(planetary)

#O objeto 'Cube' irá alinhar o eixo de visualização para o vetor[1] do planetary (y). 2=eixo, 1=fator

codeCube.alignAxisToVect(vetor[1], 2, 1)

#O objeto 'Cube' vai aplicar uma rotação Local no eixo Z+

codeCube.applyRotation([0, 0, 0.1], True)

#I don't speak english, i'm from brazil.

  • $\begingroup$ This answer doesn't have an explanation. Can you please edit your answer to explain your code? $\endgroup$ Jun 25, 2018 at 14:52
  • $\begingroup$ While I doubt answering in a different language is disallowed, I would suggest using a translator or the like. That way, the OP can at least get an idea of what you are saying (assuming they only speak English.) Welcome to BSE! :D $\endgroup$
    – krypticbit
    Jun 26, 2018 at 0:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .