Move object based on device motion

0 favourites
  • 9 posts
From the Asset Store
A futuristic device, can be used as radarscreen, optionscreen, infodisplay, research device, ...
  • I'm making an airplane shooter game for iPad in which you have a player who fires at other airplanes to destroy them. I am trying get my number of buttons down to ONE, and I want that button to be the "fire bullet" button. Therefore, I need a way to move my player without having to touch the screen. I would love if I could tilt the iPad to move the player along the X axis. Any help is appreciated. Thanks in advance! <img src="smileys/smiley1.gif" border="0" align="middle" />

  • I'm not too sure if that's possible, but you could try the "Touch" behaviour! :]

  • I tried that and found that a condition can be "Device motion supported," but once I have that I don't know what to do.

  • Adam, I haven't worked much with the Touch plug-in, but try the following and you will see the actions and methods you need to use:

    1. Create a new project

    2. In the layout, add the Touch plug-in

    3. In the layout, add a sprite

    4. In the event sheet, add an event: Touch:Device orientation is supported. This is a condition which checks to make sure that device orientation is supported. If it is, then the action will be executed.

    5. Add an action, and select your sprite

    6. Under the Size & Position section, select Set X

    7. When the prompt comes up, go to the Objects with expressions window, and select Touch

    Under the Orientation & Motion section, you will see the Acceleration methods. This should get you started. There are many others on the forums who will be able to help you with the specifics regarding the methods and the math involved.

    Good luck!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thank you! I will try that and let you know how it works.

  • Here is some simple psuedo-code for my game that moves a ball by tilting the phone (works for me on Android by exporting through CocoonJS):

    If Touch {alpha + beta + gamma)orientations NOT = 0,

    --- Sprite Set 8Direction Vector X to Touch.AccelerationYWithG * 32

    --- Sprite Set 8Direction Vector Y to Touch.AccelerationXWithG * 32

    (Sprite has 8Direction Behavior attached to it)

    Note that X and Y values are interchanged - this is done by purpose as my game is in Landscape mode and I believe the values that are being passed are assuming Portrait mode. The value 32 could be replaced by any other number - the higher the number the faster the response speed.

    Please let me know if this works for you, or if you have a better idea.

  • exertia it worked for me, thanks!

    how do i detect orientation of device? if the user flip device upside down, then it'll move to positive or negative value to fit their orientation

  • You can lock the orientation from both the project properties within Construct 2 as well as in CocoonJS.

    Otherwise, if you want to allow auto-rotation, you should be able to use these values of the Touch object to determine the orientation:

    Alpha

    Beta

    Gamma

    Return the device's orientation if supported, or 0 at all times if not supported. Alpha is the compass direction in degrees. Beta is the device front-to-back tilt in degrees (i.e. tilting forwards away from you if holding in front of you). A positive value indicates front tilt and a negative value indicates back tilt. Gamma is the device left-to-right tilt in degrees (i.e. twisting if holding in front of you). A positive value indicates right tilt and a negative value indicates left tilt.

  • guess i'll just lock it, save some unnecessary problems, thanks!

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