Lets say I wanted to have a character sprint at full speed for 3 seconds and afterwards fall off to a fatigued sprint. How would make my characters sprint speed of 1.5 then after 3 seconds smoothly lower the sprint speed to .6
I used a timer property in a prototype and it worked ok-ish but it got confusing and i didn’t have much control of the speed. I’m using the character physics type and .applyMovement, should I change the physics type and use a different type of motion to achieve this?
If keypressforward.positive and own.localLinearVelocity.x<5 and own['Timer']<=44:
Own.applyForce((100,0,0),1)
own['Timer']+=1
else:
if keypressForward.positive:
own.localLinearVelocity.x<2.5:
own.applyForce((70,0,0),1)
else:
If own['Timer']>=1:
own['Timer']-=1
I think an increment in speed is the way to go. That means you add a constant value on top of the existing speed. This is what force on physics types is doing. It results in an acceleration until the sum of the forces are balanced.
I never used Character Type. From what I see it is not a physics object. This kind of object gets teleported to drop to ground.
When you use the motion actuator (in Character Motion mode) you can reconfigure the parameters via Python. If you use pure Python you can do it in a similar way … apply the concept to your code.
demo.py
PROPERTY_INCREASE = "increase"
PROPERTY_MAX = "max"
X_AXIS = 0
def increaseX(controller):
# add sensor checks here
actuator = controller.actuators[0] # quick and dirty grab the first actuator
dLoc = actuator.dLoc
value = dLoc[X_AXIS]
owner = controller.owner
maxValue = owner[PROPERTY_MAX]
if value < maxValue:
increase = owner[PROPERTY_INCREASE]
newValue = min(maxValue, value + increase)
dLoc[X_AXIS] = newValue
actuator.dLoc = dLoc
Usage:
property increase: 0.01
property max: 1.0
Any sensor to request motion [enable True Level Trigger] -> Python Moduledemo.increaseX -> Motion Actuator
You need another AND controller that activates the Motion Actuator. The Python code does not do that (but you can add it if you like).