- Home /
Does exists a solution to remove flickering of the Wiimote gyro ?
I want know if exists a solution, or some parameters, to remove flickering of the Wii Remote Plus, because I made a little game application, that involves the Physics, but the objects flicker too:
In the scene, the dynamic objects slide over a table, and the Input behavior of the Wii Remote Plus gyroscope, is not the same as the input behavior of the arrow keys, on the Keyboard !
The flickering of input (I think), is because Wii Remote Plus, reads 60 times per second the processing signal; thus, it is not very much smoothly by rotating objects with gyroscope!
1)Does exists some adjustable parameters on “PPJoy”? (the "Timing", in the version 0.8.4.5 are disabled (grayed out), and cannot be modified at all!)
2)Does exists some options on “Glovepie 0.45”, to add some scripting line code, that smooth the rotational movements of the gyro, of the Wii Remote Plus?
3)Do anything know if exists some Physics parameters, that should be adjusted in “Unity3D v.3.4.2f5” ?
Where can I get more information?
Anyone have a suggestion?
Help, please!
Thanks! Horsepower.
Answer by aldonaletto · Mar 25, 2012 at 03:38 PM
I don't know what exactly the gyroscope returns, but if it's a Vector3 you can use a Lerp filter to smooth out the values read - that's often used with Input.acceleration, a very jerky signal without any filtering.
Supposing you're reading the gyroscope value in a Vector3 variable called gyro, you could use this:
var smoothGyro: Vector3 = Vector3.zero; // smoothed gyro value var speed: float = 1.5; // the lower the speed, the higher the smoothness
function Start(){ while (true){ // filters the gyro value continuously: var gyro:Vector3 = //<- read the gyro value and assign it to this variable smoothGyro = Vector3.Lerp(smoothGyro, gyro, speed*Time.deltaTime); yield; // repeats the loop next update } } The variable smoothGyro contains a filtered version of the raw gyro signal - read it when needed.
Answer by Horsepower · Mar 25, 2012 at 05:28 PM
I don't use Input.acceleration Script.
I use GlovePIE 0.45 that interfaces to Unity3D, to have more control, and it is more simple (I think!).
Thus, Yes!: I have used "Lerp" filter to smooth out the values.
My modified "Rotate Behaviour Script", that finally I already writed, run correctly.
I hope I've done a good work to compile it, in that manner! I am not sure, but it works without errors:
var maxVert: float = 90; // define the max vertical angle (to each side) var maxHor: float = 90; // define the max horizontal angle (to each side) private var initRot: Quaternion;
function Start(){ initRot = transform.rotation; }
function Update(){ var angV = Input.GetAxis("Vertical") maxVert; var angH = Input.GetAxis("Horizontal") maxHor; var target = initRot * Quaternion.Euler(-angV, 0, angH);
// Dampen towards the target rotation
transform.rotation = Quaternion.Slerp(transform.rotation, target, Time.deltaTime * 2);; }
Do it's correct?
It run OK!
And smooth very well the signal;
IF I put:
"Time.deltaTime * 1)"
it is more smoothed but exaggerated; the input command doesn't respond very quickly to gyroscope...
Instead with:
"Time.deltaTime * 2)"
it's OK!
Yes, I think this may do the job. Should you experience any problem with Quaternion.Slerp (object rotating about the wrong axis at some points), try to smooth out the angles ins$$anonymous$$d:
var curEuler = Vector3.zero;
function Update(){ var angV = Input.GetAxis("Vertical") maxVert; var angH = Input.GetAxis("Horizontal") maxHor; // damp the angles: curEuler = Vector3.Lerp(curEuler, Vector3(-angV,0,angH), Time.deltaTime 2); transform.rotation = Quaternion.Euler(curEuler) iniRot; } NOTE: I suspect that the correct order is Quaternion.Euler(...) iniRot, ins$$anonymous$$d of iniRot Quaternion.Euler(...) - the rotations are applied right to left in quaternion multiplication. If the order is wrong, you will notice a weird behaviour only when the object has a non-zero initial rotation.