[sorry about taking over your thread, bdsmokey]
Smooth() has a number of issues besides the 30 frame limit. Since it's based off of time, there's always going to be the issue of lag whenever it's set above a certain amount. The smooth amount also has to be an integer and it cannot be a variable. While it's really easy to put in a script, it's really not the best thing for all circumstances.
A Low-Pass filter, on the other hand, has none of those limitations. It's based off of the current position only, not positions from previous frames. It's just going to go from where it already is to wherever the input is pointing it to. You can also use a variable for the strength of the filter, like with the MouseWheel in the example below. (You can even link the strength of the filter to the speed of your motions. For example, you can make it so holding a Wiimote steady will increase the filter for more accuracy, while moving the Wiimote will lessen the filter for more responsiveness.)
- Code: Select all
// Comparison of a Low-Pass filter with Smooth()
// WASD moves cursors. MouseWheel adjusts speed of Low-Pass cursor.
// Cursor 1 = Low-Pass
// Cursor 2 = Smooth()
PIE.FrameRate = 20hz // slowed down for demonstration
var.X = - A + D // keys for left & right
var.Y = - W + S // keys for up & down
var.DefaultSpeed_X = .205 // Use any number between 0 and 1.
var.DefaultSpeed_Y = .205 // Can also be another variable.
// the mousewheel will adjust both Speed values
if mouse.WheelUp then var.Speed_Adjust = var.Speed_Adjust + .001
if mouse.WheelDown then var.Speed_Adjust = var.Speed_Adjust - .001
// applies mousewheel adjustment, keeps speed above 0
var.Speed_X = abs(var.DefaultSpeed_X + var.Speed_Adjust)
var.Speed_Y = abs(var.DefaultSpeed_Y + var.Speed_Adjust)
// LowPass filter
var.LowPass_X = var.LowPass_X * (1 - var.Speed_X) + var.X * var.Speed_X
var.LowPass_Y = var.LowPass_Y * (1 - var.Speed_Y) + var.Y * var.Speed_Y
// Smooth() filter
var.Smooth_X = Smooth( var.X , 15) // Use an integer from 1 to 30.
var.Smooth_Y = Smooth( var.Y , 15) // Cannot be a variable.
// LowPass cursor, placed on the left
cursor1.x = var.LowPass_X*.2 + .35
cursor1.y = var.LowPass_Y*.2 + .5
// Smooth() cursor, placed on the right
cursor2.x = var.Smooth_X*.2 + .65
cursor2.y = var.Smooth_Y*.2 + .5
debug = "[ Speed_X = 0." + int(var.Speed_X * 1000) + " ] [ Speed_Y = 0." + int(var.Speed_Y * 1000) + " ]"
Or to simplify that all:
- Code: Select all
var.LowPass_X = var.LowPass_X * .8 + (- A + D) * .2
var.LowPass_Y = var.LowPass_Y * .8 + (- W + S) * .2
cursor1.x = var.LowPass_X/2 + .5
cursor1.y = var.LowPass_Y/2 + .5
.8 and .2 can be replaced with any two decimals which add up to 1.