Gravity manipulation

Hi guys, this is my question regarding physics

im trying to make my hero in a vertical scroller game to try to stay inside the screen.

So i created 2 listeners, one that checks if hero is hero.y < 200 pixels ( top red part) and hero.y >500 (top bottom part) and when they are inside i apply some gravity scale to make them go back up/down, the idea is for the hero to float with some vertical movement but without exiting the screen. After i tried doing this the hero will suddenly get out of control with the gravityscale.

Any idea how i can achieve this? Sorry still learning.

corona_question.png

Why not add invisible rectangles at the top and bottom that represent the ground and the sky limit.  They can be marked .isVisible = true so they won’t show up, but still have a static physics body to keep your hero contained.

Rob

I got a problem with gravity manipulation. I need to make a bird fly upward after a touch event. after the touch event the bird must glide. is there any syntax or eventlistener for when the screen is not touched?

when idle, just add some angular velocity to physics body and set gravity (0.5,-0.5)…if you get the idea

Why not add invisible rectangles at the top and bottom that represent the ground and the sky limit.  They can be marked .isVisible = true so they won’t show up, but still have a static physics body to keep your hero contained.

Rob

I got a problem with gravity manipulation. I need to make a bird fly upward after a touch event. after the touch event the bird must glide. is there any syntax or eventlistener for when the screen is not touched?

when idle, just add some angular velocity to physics body and set gravity (0.5,-0.5)…if you get the idea