This applies both to real controllers and touch ones ( es touchscreen tumblestick)
Unit Square vs Unit Circle
Analogic stick raw input is generally mapped to a unit square.Using raw input with you controlled character makes it go faster in diagonal directions.
This maybe was ok in the 80's ,but nowdays looks terrible.
To make their character move at the same speed in every direction most people use to normalize the direction vector.
Digital Vs Analog or Area vs Perimeter
Vector normalization introduces another issue with input.You controls after vector normalization are no more analog.
Everything get mapped to the perimeter of the unit circle instead to just being constrained to the unit circle area.
While this is acceptable or even wanted in some cases , on the other hand in many other cases is good to have as much precision as possible.
As Project Anarchy comes with lua scriping I wanted to share the lua source to constrain movement to the unit circle area.
finaloffset is a Vision.hkvVec3
offsetx and offesety are raw x and y axis.
finaloffset.x = offsetx * math.sqrt(1- (offsety * offsety)/2)
finaloffset.y = offsety * math.sqrt(1- (offsetx * offsetx)/2)
now you can use you finaloffset wherever you want with full analog precision.
You can also add a deadzone directly in the input mapping or after.
Analog Input Tuning
Input of this function is too linear for my taste so you generally want to map original offsetx and offsety to a curve tuned to give more control.The simplest still very effective one is the exponential curve.
The most trivial way to make this input exponential is to write
offsetx = offsetx * offsetx * offsetx
offsety = offsety * offsety * offsety
Make this just before the normalization.
Offset are just multiplied 3 times by themself to not break the sign as Raw input is in the -1 to 1 range and have to stay in this range also after multiplications.
This gives you more control in the lower range of stick movement letting you to move the character with precision at lower speed then goes fast to the max speed.
No comments:
Post a Comment