Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Accelerometer and speed control

Author
Message
JORGEMAL
15
Years of Service
User Offline
Joined: 2nd Aug 2009
Location:
Posted: 20th Feb 2012 19:12
I am testing the accelerometer in a game I am writing. There is a spaceship wich moves up and down so I am only updating the vertical movement of my iPod. Nevertheless, I would like to set no movement when my device is at about 160 degress or around direction 0.65. This way, if I want the spaceship to move up then I still can see my device's screen comfortably. I tried with something like this but the speed is faster upwards and slower downwards. What should I do to keep the speed?

numAccelerometerY = GETDIRECTIONY() - 0.65
SETSPRITEY(intSpaceshipImage, GETSPRITEY(intSpaceshipImage) + numAccelerometerY)

With respect,
Jorge Maldonado
DVader
20
Years of Service
User Offline
Joined: 28th Jan 2004
Location:
Posted: 20th Feb 2012 19:47
I've not had much success with accelerometer movement for similar reasons ( hard to see what you are doing). You would have better luck using getdirectiony()*2 or similar to increase the sensitivity, and then limit how far the object can move at the top and bottom of the screen.

Daniel TGC
Retired Moderator
17
Years of Service
User Offline
Joined: 19th Feb 2007
Location: TGC
Posted: 20th Feb 2012 21:39 Edited at: 20th Feb 2012 21:44
I developed some functions to deal with this as part of the Useful Community Functions project. Assuming what you want is for the sprite to move up, down, left and right, and set the calibration of the device to a position the user finds comfortable, then this will do the trick. I've already posted this on the forums, but here's a copy of my original post.

===========================

Here's an improved version of my accelerometer functions. The first is the same but I'll repost it anyway, the rest now have deadzone options in both X and Y, as well as sensitivity options so you can adjust the speed directly within the function. Again I used the accelerometer example from the App Game Kit examples folder as the basis for testing these functions.

Startup code:


SetAccelerometer()


float = GetDirectionYOffset(deadzone, sensitivity)
deadzone as float, range is always between 0 and 1
sensitivity as float, multiplies the outputted function value



float = GetDirectionXOffset(deadzone, sensitivity)
deadzone as float, range is always between 0 and 1
sensitivity as float, multiplies the outputted function value



example code (modified version of projects/input/accelerometer/)


=========================

The benefits of these functions, is that no matter the angle of the pad, the output value is always between 0 and 1 in both directions. So if you multiply them by x then you'll get a value between 0 and x. Also there's a deadzone setting, so your sprite doesn't twitch with every movement of the players tablet, you don't need a high value for this, at 1 it won't move at all, and 0 there's no deadzone at all, so play around with that one until you feel it's right.

Login to post a reply

Server time is: 2024-11-23 04:09:32
Your offset time is: 2024-11-23 04:09:32