Linear interpolation of property values

Hi,

this is one method to produce a linear interpolation of property values.

What it does:

Imagine you want to switch a property value from 0 to 10 in 0.1 steps, that you get[INDENT] 0.0, 0.1, 0.2 … 9.8, 9.9, 10.0
[/INDENT]and back.

Usage:
if you use the vehicle wrapper you might want to use this to make a smooth steering or power.

How to use it:

Properties:

float “value” = current value
flloat “targetValue” = the value to interpolate to

Both properties can have a name of your choice. For the next explainations I use the names as described above.

Setup:

property sensor (True Pulse!) with
mode: “not equal”
Prop: your value property name = “value”
Value: your target property name = “targetValue”

–> Python Module: Interpolation.linear

–> Property actuator with
Mode: don’t assign or add
Prop: the name of the stepSize property (than you need property “stepSize” = 0.1) or
Value: the non-zero stepSize e.g. 0.1

That is all you need for the interpolation.

Why that complicated setup?
It allows you to use the same setup for different properties at the same object. Unfortunatly you need to setup separate Python controllers for each interpolation.

But you need your own logic to set the targetValue property.

This is the setup for Method A:



and for Method B:

Please find attached the demo file with the Python module.

Attachments

Controls.blend (40 KB)

Hi Monster,

I was looking a your .blend file, and I’m a bit confused.

I use a following method for the linear interpolation. A python sample

ds = [1.0, 4.0, -1.0, -4.0] # so called data set. [value max, target max, value min, target min]

def l_i(d,i): # Linear interpolation function.       
    return d[1] + ((i - d[0])*(d[3]-d[1])) / (d[2]-d[0])

val = 0.5 # value

print l_i(ds,val) # Call a l_i function with data set and value & print result 

It’s late here and maybe I missed something :slight_smile:

While it seems to be a good setup like all the ones you make, I’m also, like usual, a bit iffy on the use of property actuators and sensors, I generally try to avoid major use of those nowadays outside of very simple logic setups because they are the most easily replaced by python code, if I need property driven scripts for more than one object types than I either do it through values in the properties window or an id property that’s a different value per-object.

Also, my first thought of seeing the thread title was linearly interpolating to a new value over a set number of frames rather than a set value per-frame, regardless of that this specific type has some good uses even though the other way of doing interpolation has uses as well.

Thanks for the comments :slight_smile:

I’m pretty sure it can easily modified to make the interpolation depend on time/frame rather than steps size. The usage depends on the specific use case.

I suggest my not linear method:

Attachments

Controls_2.blend (334 KB)