Help!! linearImpulse and applyForce

Ok.. I am not a stupid person, but I am having a difficult time trying to understand the math and logic behind these two functions (may with just my app)

Here is the scenario.. (please see pic) I have a large circle with 3 objects spaced out equally spaced around. The large circle can move around the screen. After a perform with delay – I want to call a ball to be fired/move from Obj1, Obj2 or Obj3 to the x0, y0 of the screen no matter where Obj1 is located.
With using ApplyForce or LinearImpulse – I have no idea how to find the collation between Obj1 (2 or 3) to x0,y0…
Yes I can get Obj1.x and Obj1.y and I know that I want to shoot thru x0, y0 – but how does this adapt to the arguments required in ApplyForce or LinearImpulse?
PLEASE HELP!!!
Thanks!

Thanks in advance!

I read that a few times but am having trouble taking it in - basically you want to shoot an object from one of the three circles (obj1, 2 and 3) to the center of the large circle, yes?

If so what is the large circle called? It's x and y at any given time would be the center.

Hi Peach – sorry for the confusion..

To answer the first question: Yes, I want to shoot an object (bullet) from one of the three circles (obj1, 2 OR 3) - randomly picked – but not just to the center BUT keep going.

Shooting to the center could be simulated by using a simply transition from the Obj1.x, Obj1.y to x=0, y=0 – which I have done, but I want the object (bullet) to pass thru x0,y0 and keep going in that direction.

2nd question: Let’s just call the large circle “Base” to keep it simple. The base’s (large circle) center is always at x0,y0
The reason I didn’t give x and y on the three circles (obj1,2 or 3) was because they are not a fixed location.

Hey again,

You'd likely look at something like this;

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
local base = display.newCircle( 160, 240, 120 )
base.alpha = 0.2
 
ball1 = display.newCircle( 230, 150, 20 )
 
function test ()
        if ball1.x > base.x and ball1.y < base.y then
                transition.to(ball1, {x=ball1.x-base.x*2, y=ball1.y+base.y*2})
        elseif ball1.x > base.x and ball1.y > base.y then
                transition.to(ball1, {x=ball1.x-base.x*2, y=ball1.y-base.y*2})
        elseif ball1.x < base.x and ball1.y < base.y then
                transition.to(ball1, {x=ball1.x+base.x*2, y=ball1.y+base.y*2})
        elseif ball1.x < base.x and ball1.y > base.y then
                transition.to(ball1, {x=ball1.x+base.x*2, y=ball1.y-base.y*2})
        end
end
test()

Thanks Peach - I will look at this tonight - but is there a way that you know how to do this with and impulse or apply force?

You would be able to do it but the math is escaping me at the second. You'd need to work out the balls position compared to the center of the base and do some calcs from there.

Hey
I think I understand what you are trying to do... so maybe this would do the trick:

... use the localToContent() function to get the screen coordinates of the Base relative to screen 0,0.. something like:

  baseX, baseY = base:localToContent(0,0)  

... then get the objects coordinates relative to the Bases

  objX, objY = obj:localToContent(baseX,baseY)  

... now you have an x and y value for your forceX and forceY....

... apply them to the bullet!

Would this do the trick?

Richie

.. AN AFTER THOUGHT!

... you may have to do some basic stuff to make sure the bullet fires toward the Base center and not away from the obj in the opposite direction.

ie.
Base at 160,240
Obj at 200, 200

when the objX and objY is calculated... you will need to make them negative forcex and forcey.....

This should be easy enough by checking obj X and Y coord > bases X and Y coords

Hope this helps

views:2091 update:2012/2/8 8:46:10
corona forums © 2003-2011