Change speed of f curve actuator playback

Hi all,

Simple question, how would I increase the speed of an f curve played back in an actuator?

For example, I have an animation of 100 frames. Is it possible to double the speed so the f curve plays in 50 frames instead?

Cheers

Paul

1)Make a True Pulse Always sensor, running at f:0
2)Make a keyboard sensor, for slowing the animation, and type its name in the user properties (Make it True Pulse)
3)Create a property called “frame” on the object. Set it to float
4)Set the property to “frame” in the curve ‘property’ actuator
5)Make an ipo actuator, set it to property and connect it to script. Type its name in the user properties.
#6)If you want to change the start or end frame, or speed etc, change the variables in the user properties

import bge
controller = bge.logic.getCurrentController()
owner = controller.owner

##User Variables#######

#name of the keyboard sensor (slow)
keyboard = ""
#name of the ipo property actuator
ipo = ""
endframe = 5
startframe = 1
speedfast = 1/15
speedslow = 1/30

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

slow = controller.sensors[keyboard]
ipo = controller.actuators[ipo]

if not "count" in owner:
    owner["count"] = speedfast


owner["frame"] += owner["count"]   

if slow.positive:
    owner["count"] = speedslow
else:
    owner["count"] = speedfast
controller.activate(ipo)

Cool, thanks agoose77! Amazing work as usual!

One last question- what would the script look like if I wanted the slow/fast action to work with the following logic setup:

NEAR/RAY/RADAR >>>>SCRIPT>>>>F-CURVE ACTUATOR

I ask as this would emulate the wind modifier in Unity, and allow things like flapping trees when a helicopter goes near them. Is it a matter of just changing the keyboard (and actuator) part to identify another sensor?

Ok, maybe two questions! What does [“count”] do? I assume it controls the frame playback, but I cant see it defined in the variables and it is not a property.

Anyway, many thanks for some fine work,

Paul

Basically, you can create and use properties on an object, even if they arent visible in the properties panel, just define them in python. The catch is SCA can’t interact with it, but it’s easier if you want to share code and give the user minimal work.
owner[“count”] is basically the number that python adds to the frame property each tick. If it is bigger, the frame property gets bigger faster, and so plays “faster”
So, the keyboard sensor slows down the F-Curve Play back.
Whenever it is positive, it slows down.
Easiest thing to do is make the near sensor detect the object, and click the INV button on the sensor, so that it triggers when the helicopter isn’t near, thus slowing the animation when the helicopter isn’t near.

Ah, makes sense now! Cheers for the explanation.

Paul