Move game Objects with a Master Object (Python)

Can someone please give me some advice with my work in progress BGE Demo , I have tried to figure this one out ; but my knowledge with Blender and Python isn’t that good enough yet…

Download “Galactical Balls” here : Galactical-Balls


There are 2 Blender files : “Galactical_Balls.blend” and “Reference.blend”
I made the “Reference.blend” file to use here as a reference for my question… :slight_smile:

In the Blender File “Reference.blend”, the playable balls all have the same logic bricks, when you press for example on the Up Arrow Key, all the balls move in the same direction.

[ATTACH=CONFIG]206383[/ATTACH]

I used (Add) Linear Velocity motion to get all the objects to roll on the ground and jump around.

How can I get all my Slave Balls to copy the Master Ball’s (Add) linear velocity XYZ values, instead of using 18 times the same logic brick setup as the Master Ball…

Is there a Python script that already exists for what I am trying to do! I have been searching on the Web, but no success up until now…

I think Navemesh with fake rotate is easy way (not use python).

You should be able to access the motion actuator’s logic brick and change it’s values, and then apply it:



from bge import logic

sce = logic.getCurrentScene()
cont =  logic.getCurrentController()
motion = cont.actuators['Motion']

master = sce.objects['Master'] # Replace Master with the name of the 'master ball' that you described

motion.linV = master.worldLinearVelocity

cont.activate(motion)


Note that worldLinearVelocity is a new variable that appeared in 2.64 or so, so if it doesn’t work for you, try upgrading your Blender version. Also note that this code is untested.

EDIT: As a side-note, I would use group instancing if you’re not already. That way, you could make one ‘slave’ sphere in another layer or scene and make a group out of it, then place group references of the ‘slaves’ around in the test area. If you need to go back to change it, change the referenced ‘slave’ sphere that you created.

??? :spin:
i no idea how nawmesh can do this

worldLinearVelocity work at least from 2.57 ! sure :wink:

“Also note that this code is untested.”

it should work

if not , this is tested

#######
from bge import logic

sce = logic.getCurrentScene()
cont = logic.getCurrentController()

master = sce.objects[‘Master’] # Replace Master with the name of the ‘master ball’ that you described
own = cont.owner
own.worldLinearVelocity = master.worldLinearVelocity
#######

Thank you everyone :slight_smile: Ok …

I called the script Master_Move , all you need to do is apply the python script to the objects that you want to move with the “Master” Object…

###################################

sensor “Always(TRUE)” ±----+ Python

###################################

from bge import logic

sce = logic.getCurrentScene()
cont = logic.getCurrentController()

master = sce.objects[‘Master_Ball’] # The Master object ‘Name’
own = cont.owner
own.worldLinearVelocity = master.worldLinearVelocity

###################################

Yes it works but not as expected :slight_smile:

This is weird and FUN :slight_smile:

So now my Slave Balls do copy the Master Ball’s linear velocity, but don’t fall by themselves ?..

The Slave Balls tend to stay suspended in the air !

To avoid this I used a (near sensor) with true level triggering (pulse mode) so the script will only run when the Slave Balls are near any game property (all objects).