Change gravity to object with event

Hi everyone,

I’m new to the whole programming stuff so sorry if this might be a noob question.

Well first of all,  My scenario is a top view and I have this ball that has an event already created. The event is close to the angry bird mechanics (pull, let go, and the ball moved) 

So now I’m trying to create an event on top of this one.

So this event will be applied after the first event with another touch. What I would like this event to do is to drag left and right to give the ball a curvature path , so I was thinking creating an event that changes the gravity in its x depending on the distance the finger moved left or right.

So I’m pretty clueless on how to start this, so if anyone can guide me I would really appreciate it.

Thanks in advance guys!

Hi @andrestopmo,

You can just use the .setGravity() function to change the world gravity at any time:

http://docs.coronalabs.com/api/library/physics/setGravity.html

Or if, for some reason, you want to affect only the gravity effect on the ball, you can adjust its gravity scale individually:

http://docs.coronalabs.com/api/type/Body/gravityScale.html

Best regards,

Brent

Thanks for the response, but I’m stuck on this. At the moment I’m not using gravity since its a top view and basically the gravity is on the “Z” if you will. I’m not sure now if the gravity would be my best solution for this. But let me explain my scenario a little better. So I have a field and a ball. The ball has an event that “Kicks” it when I pull and let go. So this event is the velocity of the ball. So now what I would like to do is: While I’m applying the velocity on the ball I want to use a multi touch function where my other finger would slide side to side to give it a curve to the ball (the bigger the move the more curve). What would be my best solution? I don’t really need the whole code I would just like a starting point because I have no idea how to achieve this. Thanks again!

You want to impact the ball while it is in air or not?
Maybe you should calculate delta for x at the beginning and ending of your swipe event and pass it to some apply force method and apply force horizontally in contrast to applying impulse when you pull and let go the ball.

Hi @andrestopmo,

A touch joint may be a good solution for this. Basically, that applies an invisible “rubber band” joint from the physics object to any point on the screen, with a variable (set-able) degree of pull/flex. This joint is documented along with the others here:

http://docs.coronalabs.com/guide/physics/physicsJoints/index.html#touch

Take care,

Brent

These are great idea. Thanks everyone! :slight_smile:

Hi @andrestopmo,

You can just use the .setGravity() function to change the world gravity at any time:

http://docs.coronalabs.com/api/library/physics/setGravity.html

Or if, for some reason, you want to affect only the gravity effect on the ball, you can adjust its gravity scale individually:

http://docs.coronalabs.com/api/type/Body/gravityScale.html

Best regards,

Brent

Thanks for the response, but I’m stuck on this. At the moment I’m not using gravity since its a top view and basically the gravity is on the “Z” if you will. I’m not sure now if the gravity would be my best solution for this. But let me explain my scenario a little better. So I have a field and a ball. The ball has an event that “Kicks” it when I pull and let go. So this event is the velocity of the ball. So now what I would like to do is: While I’m applying the velocity on the ball I want to use a multi touch function where my other finger would slide side to side to give it a curve to the ball (the bigger the move the more curve). What would be my best solution? I don’t really need the whole code I would just like a starting point because I have no idea how to achieve this. Thanks again!

You want to impact the ball while it is in air or not?
Maybe you should calculate delta for x at the beginning and ending of your swipe event and pass it to some apply force method and apply force horizontally in contrast to applying impulse when you pull and let go the ball.

Hi @andrestopmo,

A touch joint may be a good solution for this. Basically, that applies an invisible “rubber band” joint from the physics object to any point on the screen, with a variable (set-able) degree of pull/flex. This joint is documented along with the others here:

http://docs.coronalabs.com/guide/physics/physicsJoints/index.html#touch

Take care,

Brent

These are great idea. Thanks everyone! :slight_smile: