help with accelerometer

Game Editor comments and discussion.

help with accelerometer

Postby Nykos » Mon Jun 06, 2011 6:18 am

Hey everybody, I'm on a new game and this time i'd like to use the accelerometer.

I asked alexandrefredenucci who gave me the link to the accel.ged demo, and i tried it in my game.

For the ones who know this demo, i just copied the "draw actor" script from the ball, to a "draw actor" script in my player. And it works, but...

There are two problems: First, i'm making a doodle jump like game, so the phone needs to be hold normaly. But if i hold it that way, the player receives orders from the accelerometer to move on the right. I have to turn the phone 90° to the left if i want the player to stay calm. In fact it acts like if the game was meant to be played in 480x320 resolution. How can solve it?

Then, seeing this, i thought maybe i could try to tweak a little the script values, but the editor is not all right with it.
Every time i try to change a value, i receive an error " re-decleration of macro"
What should i do?

Thanks in advance, nikos
Nykos
 
Posts: 110
Joined: Sun Dec 19, 2010 11:11 pm
Score: 6 Give a positive score

Re: help with accelerometer

Postby skydereign » Mon Jun 06, 2011 6:31 am

Well I haven't re-set up my geplayer, so I can't test if this works, but if the sensor is not changing when your game's resolution changes, I think you need to change the xvelocity call to yvelocity -=, and the xvelocity to yvelocity +=.
Code: Select all
yvelocity -= ax * SDL_IPHONE_MAX_GFORCE / SINT16_MAX * GRAVITY_CONSTANT * MILLESECONDS_PER_FRAME;
xvelocity += ay * SDL_IPHONE_MAX_GFORCE / SINT16_MAX * GRAVITY_CONSTANT * MILLESECONDS_PER_FRAME;


Of course I this still assumes you are holding it perfectly flat. But if you hold it vertically it should move you down. Now if you want to adjust the angle that counts as balanced (so you can hold it somewhat tilted and not have it move), then you just add a +/- to the end of the code from above. Not sure why it is saying you are redeclaring macros, editing it worked fine for me. You can always remove the macros from that script though, and either put them in global code, or replace them with the constants.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: help with accelerometer

Postby Nykos » Mon Jun 06, 2011 7:56 am

wow, not sure i understood everything but thanks a lot sky, will try it this morning
Nykos
 
Posts: 110
Joined: Sun Dec 19, 2010 11:11 pm
Score: 6 Give a positive score

Re: help with accelerometer

Postby Nykos » Mon Jun 06, 2011 8:33 am

Thanks a lot man, it works just fine. I still can't edit the values, even in global code, so i 'll have to find out why but this is still good.
Nykos
 
Posts: 110
Joined: Sun Dec 19, 2010 11:11 pm
Score: 6 Give a positive score

Re: help with accelerometer

Postby jimmynewguy » Mon Jun 06, 2011 1:03 pm

You can also use a vector if you want. Maybe that will be easier to understand/edit for you?

Code: Select all
Vector v = getAccelerometer();// in global code

then you can use v.x and v.y they show how "tilted" the accelerometer is from 1.0 to -1.0
Code: Select all
xvelocity = v.x * 10//fastest the player could move is up to 10 pixels per frame

hope you understand, just ask if you don't. You still might need to play with making it -= or += to get it as holding the iphone straight up
Working on a probably too ambitious project! Wild-west-adventure-RPG-shooter-thing.
User avatar
jimmynewguy
 
Posts: 1137
Joined: Sat Mar 31, 2007 6:27 pm
Score: 89 Give a positive score


Return to GE - General

Who is online

Users browsing this forum: No registered users and 1 guest

cron