Problem in applying force

Hello,

I am using projectile in my project similar to that in Hot_Cross_Bunnies-Tutorial-master but getting problem in force. If I stretch band less and release, force is not applied properly on that and bun is not moving in proper direction. But when I stretch the band more and release, it is working properly and bun is moving in proper direction with proper projectile.

Here is the attached file. Please suggest me what to do in this case.

Thanks in advance.

Hi @akshada.sapre,

Most of your code looks OK at a quick glance, so there must be some issue with the parameters that you’re passing to applyForce(). Make sure that you’re properly considering the screen location of the sling, and then using the proper offset compared to the event.x and event.y upon release.

Best regards,

Brent

i have checked parameters of applyForce() and tried all possible changes in parameter value. But it is still giving the same problem. All I want is when I release the bun, it should move in proper direction.

Hi @akshada.sapre,

When I ran the program, it seemed that the force was not being applied in relation to the sling location, but instead some other location on the screen. This might explain why it works sometimes, but not always.

Brent

Okay I got this but I am new to corona and these terms are very new to me. I am not getting what to change in code so that it will work properly. Please tell me where and what to make changes in that.

Hi @akshada.sapre,

It’s best if you learn how this process works, why, and where to adjust the code, otherwise you’ll encounter difficulties later. The touch “event” occurs at a specific place on the screen, so you’ll need to apply the force to the object based on the difference between that touch location and the sling location, negated since the force is applied from the other side. For the x part, it might be this:

[lua]

(event.x - sling.x) * -1

[/lua]

But that will probably be far too much force to apply to the object (based on its density), so you should factor it down by a reasonable value… -100, -1000, -5000, whatever seems good in the simulation.

[lua]

(event.x - sling.x) * -1000

[/lua]

Brent

Hi @akshada.sapre,

Most of your code looks OK at a quick glance, so there must be some issue with the parameters that you’re passing to applyForce(). Make sure that you’re properly considering the screen location of the sling, and then using the proper offset compared to the event.x and event.y upon release.

Best regards,

Brent

i have checked parameters of applyForce() and tried all possible changes in parameter value. But it is still giving the same problem. All I want is when I release the bun, it should move in proper direction.

Hi @akshada.sapre,

When I ran the program, it seemed that the force was not being applied in relation to the sling location, but instead some other location on the screen. This might explain why it works sometimes, but not always.

Brent

Okay I got this but I am new to corona and these terms are very new to me. I am not getting what to change in code so that it will work properly. Please tell me where and what to make changes in that.

Hi @akshada.sapre,

It’s best if you learn how this process works, why, and where to adjust the code, otherwise you’ll encounter difficulties later. The touch “event” occurs at a specific place on the screen, so you’ll need to apply the force to the object based on the difference between that touch location and the sling location, negated since the force is applied from the other side. For the x part, it might be this:

[lua]

(event.x - sling.x) * -1

[/lua]

But that will probably be far too much force to apply to the object (based on its density), so you should factor it down by a reasonable value… -100, -1000, -5000, whatever seems good in the simulation.

[lua]

(event.x - sling.x) * -1000

[/lua]

Brent