Set Axis & Accelerometer

0 favourites
  • 14 posts
From the Asset Store
A whole set you need to create a gorgeous winter 2d game
  • 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


  • 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..

  • 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?


  • 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.

  • Thanks for the insight, I'm gonna spend the night tryna figure it out.

  • 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 :

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




    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?

  • 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.

  • Current Event Sheet:

    <img src="" border="0" />

    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.


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

    Set startbeta to touch.beta at start of layout.

  • Yeah I just finished doing that - I set the startbeta to touch.beta on start of layout - I still have to hold the phone flat to move. The controls work fine I just dont know which expressions determine the angle/position the phone is being held.

    Event sheet:

    Example with flat zero point:

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Is there a way I can use the cos & sin system expressions to set the zero point to the phones position/angle?

  • Please remove the every tick action.

    It makes the action on start of layout pointless.

  • Okay will do.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)