Set Axis & Accelerometer

Get help using Construct 2

Post » Fri Jan 03, 2014 8:02 pm

I want to make a game that uses the touch accelerometer feature, where the player can use 8 Direction movement. How do I set this up & in a way that the axis is set at the start of the layout.

- The player should be able to hold the phone at different angles but the axis is set on the start of the layout so based on that the player can move (8-Direction) using the accelerometer


Example:


https://www.dropbox.com/s/ytn6oqzn5k6irst/Accelerometer.capx
B
6
S
2
Posts: 151
Reputation: 1,366

Post » Fri Jan 03, 2014 8:15 pm

You could set a global variable for alpha beta and gamma difference on button pushed or any other event and subtract that difference from the alpha beta and gamma values every tick from that moment on..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Fri Jan 03, 2014 10:22 pm

Okay, I'll try that out. I think that might work for setting the axis but even then I'm wondering how does subtracting that difference upon start of layout or on button pushed allow me to use the accelerometer if I have to make up a value for the global variable

& If I'm subtracting that difference every tick how would I write that code. Every Tick - Subtract [Difference] from Global Variable ? or from Alpha Beta Gamma?

Thanks
B
6
S
2
Posts: 151
Reputation: 1,366

Post » Fri Jan 03, 2014 10:29 pm

In the events you use the alpha beta and gamma values just subtract the difference. so instead of if alpha>20 it would become if alpha-difference>20

so just replace each alpha with (alpha-difference)

This is just theoretical, for I've never tried it myself.
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Sat Jan 04, 2014 4:10 am

Thanks for the insight, I'm gonna spend the night tryna figure it out.
B
6
S
2
Posts: 151
Reputation: 1,366

Post » Tue Jan 07, 2014 9:35 pm

I wasnt able to set the axis on the start of layout. Setting the axis on the start of layout allows for the player to hold the phone at different angles without compromising the touch controls which are accelerometer based.

I did learn tho that I could create a variable for "Axis" and set its value to: "Touch.Beta & Touch.Gamma". I would do that for both On Start of Layout & Every Tick but how would I set the appropriate controls since I need to compare the orientation to a value

Seems like theres a Million and twenty plus incorrect ways of doing this & I'm hoping to minimize Trial & Error on this particular obstacle.

Give it a Try : https://www.dropbox.com/s/ytn6oqzn5k6irst/Accelerometer.capx
B
6
S
2
Posts: 151
Reputation: 1,366

Post » Tue Jan 07, 2014 10:51 pm

I'm not sure if this will work, but couldn't you create three global variables:

-startAlpha
-startBeta
-startGamma

and on start of layout set startAlpha to Touch.Alpha etcetera?

you could also choose to make a button which the player could touch on the moment he or she wants the phone/tablet to be considered straight and set the values on touch.

after that you should use touch.alpha-startAlpha to get the correct alpha value..

I would try it this way, but if this works?
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Wed Jan 08, 2014 4:38 pm

Haven't tried implementing it, but LittleStain's second and third posts seems to be the good idea to go with and to implement.

I don't know where you get the "Touch.Beta & Touch.Gamma" from, I have no idea how it can make any sense since it's concatenation.
New to Construct ? Where to start

Image Image

Image Image

Please attach a capx to any help request or bug report !
Moderator
B
296
S
119
G
96
Posts: 7,328
Reputation: 71,298

Post » Wed Jan 08, 2014 5:58 pm

Current Event Sheet:



The events currently in the game allow for true 8 directional tilt movement, even setting the balls position to scollx & scrolly at the start of the layout.

The trouble I'm having now is setting the axis on start of layout so the controls can be based off the angle to player is holding the phone instead of a fixed number. I.e Player should be able to use the accelerometer controls wether the phone is horizontally upright or horizontally flat.

Ex: https://www.dropbox.com/s/ytn6oqzn5k6irst/Accelerometer.capx
B
6
S
2
Posts: 151
Reputation: 1,366

Post » Wed Jan 08, 2014 6:15 pm

Ok, I don't understand why are you setting startbeta to touch.beta every tick?

Set startbeta to touch.beta at start of layout.
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Next

Return to How do I....?

Who is online

Users browsing this forum: SnipG and 9 guests