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…
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…
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…
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.
master = sce.objects[‘Master’] # Replace Master with the name of the ‘master ball’ that you described
own = cont.owner
own.worldLinearVelocity = master.worldLinearVelocity
#######
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).