Rotation with Accelerometer
Jugger
Member, PRO Posts: 238
Hi guys
Need help.
How to make a smooth rotation of the object using the accelerometer in the left and right
by 45 degrees.
And to return the object to back position (0 degrees) if accelerometer=0
Thank you very much
Need help.
How to make a smooth rotation of the object using the accelerometer in the left and right
by 45 degrees.
And to return the object to back position (0 degrees) if accelerometer=0
Thank you very much
Comments
if accelerometer rotation = x amount,
...................
Timer: every 0.1 second
if object rotation = < rotated left 45 degrees.
rotate left 1 degree
...................
Never done it myself so this is just how I would approach it, someone else may be able to advise in more detail.
so if the accelerometer rotation is detected at a certain value,
check every 0.1 seconds to see if actor has rotated to 45 degrees, if it has not, rotate one degree and check again.
You'd need another rule for rotating right.
Yes! it almost works, but the movement is not smooth. (
I need that would angle object depended on the angle of inclination of the accelerometer, but limited to 45 degrees.
And if the accelerometer = 0
object is returned to 0 degrees
Thank you.
if accelerometer rotation = 5 degrees,
Timer: every 0.1 second
if object rotation = < rotated left 5 degrees.
rotate left 1 degree
if accelerometer rotation = 10 degrees,
Timer: every 0.1 second
if object rotation = < rotated left 10 degrees.
rotate left 1 degree
if accelerometer rotation = 15 degrees,
Timer: every 0.1 second
if object rotation = < rotated left 15 degrees.
rotate left 1 degree
etc etc...
maybe not increments of 5, but you get the idea, I would imagine it should be do able otherways but I think it has failed for some reason.
What should work (but might not)
..........
if accelerometer > 0
if actor rotation < accelerometer angle
Timer: every 0.01 second
change actor angle to actor rotation + 1
..........
then you'd need to repeat the rule, if the angle is for than the accelerometer,
and again if the accelrometer < 0
.......
Not on my GS machine, but something along those lines might work. As I said before not tried it myself.... fingers crossed...
....
As for returning to 0,
add a rule, if accelrometer angle = 0,
actor rotation = 0...
(or if you want to be smoother, use a timer and increase the angle in degrees like before)
But the movement as a clock (((it is not beautiful (
good luck
Jon
self.rotation = vectorToAngle(device.accelerometer.y, device.accelerometer.x * -1)
smooth movement:
rotateToAngle: angle: vectorToAngle(device.accelerometer.y, device.accelerometer.x * -1) relativeTo: scene
yes, i know x and y are flipped and yes x is multiplied by -1 because the normal GS game view is landscape, yet the accelerometer inputs still map to the device's physical x,y dimensions so you need to transpose x and y and flip x by -1.
I haven't tested this.
And with which rule is applied?
rotateToAngle: angle: vectorToAngle(device.accelerometer.y, device.accelerometer.x * -1) relativeTo: scene
I'm traing
files.me.com/jugger/wmmh3o
But get panicky movement in all directions. (