4
$\begingroup$

For example, Is it possible to control a value on a motion actuator by linking it to the value of a set property? For example movement speed that can be changed on the fly by changing the property value, to change the speed?
If not possible solely using logic bricks then how would you do this using script? Would prefer logic bricks though.

(Using the picture as reference) Basically I just want the value of the X Rotation (second red box) to mirror what ever the value is of the property sp1 (first red box).

screenshot

$\endgroup$
2
$\begingroup$

put this script in a python_controller linked to a property_changed-sensor and your motion-sensor. name the property_changed-sensor "set_X"+sth to set x

import bge
cont = bge.logic.getCurrentController()
sens = cont.sensors[0]
act  = cont.actuators[0]
own  = cont.owner
if sens.name.startswith('set_X'): act.linV.x = float(own[sens.propName])
if sens.name.startswith('set_Y'): act.linV.y = float(own[sens.propName])
if sens.name.startswith('set_Z'): act.linV.Z = float(own[sens.propName])

be aware that this will not activate the motion. it will just set its parameters.

$\endgroup$
4
$\begingroup$

I don't think there is a way to achieve that with logic bricks but a small python script can. Simply paste this into a text block in blender's text editor and use the text block name in the python controller.

import bge
from mathutils import Vector

cont = bge.logic.getCurrentController()
own = cont.owner

sens = cont.sensors['Keyboard']
actu = cont.actuators['Motion']

actu.dRot = Vector((own['sp1'],0,0))

if sens.positive:
    cont.activate(actu)
else:
    cont.deactivate(actu)

enter image description here

The script should explain itself fairly well. By getting the controller object we can then get the owner and the sensor and actuator that we are interested in. We use the owner to access the game property own['sp1'] to alter the actuator values.

If you place the line print(type(actu)) you can find the type of actuator and lookup it's properties in blender's api reference. eg the simple motion actuator identifies as a KX_ObjectActuator

The last few lines activate or deactivate the motion actuator based on the output of the sensor.

$\endgroup$
2
$\begingroup$

You can use your speed-controlling property "S" to set the frequency of a timer loop (based on a timer property, eg "T"). An Always sensor (with True level triggering enabled) can then tickle an Expression controller containing (eg.) "T>S"... True pulses from the controller go to a property actuator (to reset the timer to zero) & a motion actuator (to give a jiggle of movement, preferably as dampened force). Smaller S = denser pulses = greater speed... & we're rolling!!!

I hereby award myself 1st prize for not resorting to that ghastly python gibberish (as requested in the original post) :-)

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.