I am trying to have an object be controlled horizontally via the accelerometer, however I want to control the vertical motion via another method that doesn’t use the accelerometer.
My issue is that if I am using an event to move the object based on tilt, I have to keep feeding a value for the y portion as well when I use physics.setGravity(x, y)
Is there a way I can ONLY send the X value through that function, and ignore the y parameter?
The problem in passing 0 is that whenever I tilt the device it sets the y component of gravity to something I don’t want. I want to control the y component with a button press, and completely independent of the tilt event; basically whenever the button is pressed, the y gravity is reversed, and the object begins to accelerate upwards.
I am pretty new with all of this, so chances are I am approaching this in a very odd way
Why not just store your value you wan they Y to be in a variable, and just pass that to setGravity? [import]uid: 34551 topic_id: 8679 reply_id: 31711[/import]
Thanks gamehkmail and Stevedbarlow for the replies.
stevedbarlow: That’s actually what I am trying right now, but it’s behaving sluggish and overall very awkward, my guess because I have two different listeners calling different methods to affect one of the directions independently of the othe, so they don’t seem to be playing nice.
I am gonna go a bit more the route that gamehkmail suggested. I am going to keep the ygravity component the way i have it and work my own movement logic for the horizontal movement, as for what I want to do I have a feeling gravity won’t be the right direction based on what I am seeing.
I am not sure about gravity, but I know it’s not possible to set x or y component independently of a velocity. I mean, even if one tries to get the x,y velocity first and then put back either x or y unchanged and change the other, that “unchanged” component will be changed as well.
What I am doing now is to implement my own velocity and acceleration logic by capturing enterFrame event. With this, pause and resume can then be easily implemented as well. Hope it helps.