Accelerometer Controls Roll Ball in Exact Direction of Tilt

JoshKahaneJoshKahane Member Posts: 470
edited November -1 in Working with GS (Mac)
Hi

I was wondering if it was possible to have it so that my ball in Trouball has tilt controls. But I don't just want tilt up and move up, left, right and down. Is it possible to have ti so that the ball moves in the very direction of the tilt? Any help much appreciated, thanks.

Kind regards,
Josh.

Comments

  • scitunesscitunes Member, Sous Chef Posts: 4,047
    check out the wiki and use accelerate rather than move. Use a max speed.
  • JoshKahaneJoshKahane Member Posts: 470
    Wiki has been checked. Sadly it doesn't really answer it, unless I my eyes are getting worse then they already are. :) Thanks though scitunes. Anyone have any ideas as to how this can be done?
  • ORBZORBZ Member Posts: 1,304
    you want it to move with a speed relative to the magnitude of the tilt.

    something like this:

    direction = angleToVector(accelerometerX, accelerometerY)
    speed = 100*magnitude(accelerometerX, accelerometerY)

    of course you'll want to play with the constant 100. Magnitude will be a normalized vector between 0 and 1. Of course, if you are viewing in landscape mode you'll need to transpose X and Y.
  • scitunesscitunes Member, Sous Chef Posts: 4,047
    The reason I thought using accelerate instead of move would work is that if you tilt diagonally you are changing both the X and Y and because you are using accelerate and not move the ball should move in a natural "labyrinth" style. What Orbz posted sounds good, though I've never tried it.
  • ORBZORBZ Member Posts: 1,304
    accelerate would probably be better than move, scitunes is correct it will give the feeling of mass you are looking for.

    The rules would be the same for what I said before though, just use the Accelerate instead of the Move behavior but with the same direction and speed logic i stated above.

    Of course, if you use accelerate you'll also want to add some Drag.
  • JoshKahaneJoshKahane Member Posts: 470
    This works great guys thanks!
  • UtopianGamesUtopianGames Member Posts: 5,692
    Is there any chance you could make a demo of this ORBZ? i'm playing around with tilt controls atm and would love to have a look.

    Darren.
Sign In or Register to comment.