Accelerometer movement
FanStudioUK
Member Posts: 459
I want to use in my game the accelerometer movement.
I want to know who tested it and if it's running smooth.
I have the iPhone in landscape mode and I need my player to move left or right depending on how you tilt the device.
Any help would be appreciated.
Thank you!
I want to know who tested it and if it's running smooth.
I have the iPhone in landscape mode and I need my player to move left or right depending on how you tilt the device.
Any help would be appreciated.
Thank you!
Comments
Constrain attribute: self.Position.X To: self.Position.X + (15*game.Accelerometer.Y)
That's what I was looking for!
Dead men tell no tales, right?
Cheers mate!
You should avoid constrainig attributes to themselves.
Better:
Constrain linearVelocityX to accelerometer*100
Please reply to my email when you'll have time
Hehe...
The glitchyness I'm talking about is something gendai specifically warned us about back in 0.8.x. Whenever we constrain a variable to itself we are, in effect, tying the performance of that variable to the speed of the cpu (the fps). That means that on faster hardware the x slider in your example will tilt faster and on slower hardware it will tilt slower. This is what's called cpu-bound. To prevent this we need to make the simulation time-bound, that is, that time is non-varying (well at least on earth) and so we can use it as a constant to which everything else is measured.
LinearVelocity is a measure of distance over TIME. (An easy way to remember that velocity is a measure of distance over time is Miles PER Hour = mph = miles/hour = distance/time) So long as we have time buried in our equation somewhere, then motion becomes fluid and it doesn't matter how fast or slow the cpu is it will always move the same distance over the same period of time. Simply setting the linearVelocity parameter tells the physics engine to compute distance over time.
In the prior method of constraining x position to itself we are saying to move the position of x every cpu tick, which may or may not look good on different hardware.
The reason you can't see a difference right now is because GameSalad is so damn slow. But if / when GameSalad has major performance improvements self constraining attributes will cause weird timing glitches. Things that were moving at a good speed before will suddenly zip around waaaay to fast.
Ahh... math before breakfast... yum.
I used your suggestion and it works like a charm. Made things much better.
Cheers