iOS Accelerometer Issue controlling character.

mataruamatarua Auckland, New ZealandMember Posts: 854
I have an issue with my game, the actor controlled by accelerometer with this code constrain attribute > self.Position.X self.Position.X +(15* game.Accelerometer.Y ) which works great... but the problem is when the character collides with a vertical object, it just sticks, as the constrain attribute overrides the bounce behaviour.

Is there a way to bounce off the vertical object considering the accelerometer value can be quite high. The best example I can think of is something like a wooden labyrinth set-up.

Currently I am sticking to things like Super Meat Boy and I don't want that.

Pinball style is what I am after, the harder you hit the more you bounce back.

Any help would be much appreciated :)

Comments

  • mataruamatarua Auckland, New ZealandMember Posts: 854
    I have been using all the motion attributes to try and solve this and I am getting close using a combination of change attribute on actors X and interpolate actors X -## over a short time. It does not feel like a normal bounce, but it solves a lot of issues.

    Is there a way to track an actors velocity and then use that as a variable to make a bounce bigger based on the actors speed? That is an idea I will look in to...

    It's kind of like bouncing a basketball on Jupiter due to the accelerometer. We want to play normal basketball in a heavy gravity environment.

    Up and down bouncing is fine, it's just left and right that gets overpowered by the accelerometer.
  • mataruamatarua Auckland, New ZealandMember Posts: 854
    Best result is semi-rapid head banging. Head bang too much and you get a headache and then you die, that's the answer. That I could work out :D

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    Try something like this.

    Set up the walls with physics like this:
    Density = 100
    Friction = 0
    Bounciness = 0
    Fixed Rotation = checked
    Collision Shape = rectangle


    Then in the ball actor set up the physics like this:
    Density = 1
    Friction = 0
    Bounciness = 0
    Fixed Rotation = unchecked
    Collision Shape = circle

    Then in the ball actor use the following behaviors:

    Collide
    -- Bounce when colliding with: actor of type: wall

    Timer -- every .2 seconds
    --Accelerate:
    ----Direction: (vectorToAngle( game.Accelerometer.X , game.Accelerometer.Y )+90)%360
    ----Relative To: Scene
    ----Acceleration: 300
  • mataruamatarua Auckland, New ZealandMember Posts: 854
    @RThurman thanks for that, it's not quite yet doing what I want I will have a play with it however and see if I can use that :) much appreciated!
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    @matarua -- You are welcome. Once you get it working you can tweak the numbers to get it to respond how you want.

    Oh -- I see an error. The ball needs a bounciness of .95 or higher.

    The +90 is for landscape left rotation. If the game is in portrait mode remove the +90.

    To get it to be more responsive/quicker/better make the timer smaller. (.1 is twice as fast as .2 etc.)

    The slower the acceleration, the more precise the game will feel.

    Hope that helps!
  • mataruamatarua Auckland, New ZealandMember Posts: 854
    Thanks again, yes I had a play with the settings and will do some more experiments when I don't have to do so much work, phew, it's busy times! Tonight hopefully :)
  • mataruamatarua Auckland, New ZealandMember Posts: 854
    Oh and a comment on the +90 could that be replaced by the in Gamesalad game.Screen.Device Orientation attribute?
  • cbtcbt Member Posts: 644
    I think if you change your constrain on the ball to "constrain every 0.1 seconds" your problem will be solved. If it is not smooth try every 0.01 seconds.
Sign In or Register to comment.