0
votes

I am having an circle in the center of the world. I add some balls to the world in the form of b2Body. Now i want to move or throw the ball to the center of the screen. The effect should be like the balls are colliding with the circle.

The ball are positions randomly, so they can be at any were on the screen and the need to travel to center of the screen to the circle

Can any one tell me how to do this because i have no idea to move the b2Body object.

I want blue circle to attract red circles

I want blue circle to attract red circles. Or in other words i want red circles to move to blue circle.

2
I want to it by using force & gravityJay Gajjar
ah, just the concept: every step add a force to every body with direction towards center. The amount of gravitational pull (the applied force) falls of by square over distance, ie twice the distance means a quarter of the force. However in games this may need to be tweaked because the effect of gravity might quickly be nullified with a very short distance, or it might seem to never fall off (same gravitational pull everywhere) - depends on the scale, requires experimentation.LearnCocos2D
How do i add direction to the center of my bodies and how do i differentiate red circle and green circle?Jay Gajjar

2 Answers

1
votes

Finally got the solution of my problem. I use the concept of radial gravity.

http://www.vellios.com/2010/06/06/box2d-and-radial-gravity-code/

0
votes

In this case, I am not sure about this way but you can try this way. I guess you are adding b2body by touching on the screen. Now i don't know what is the type of your B2body. There are two ways to move the b2body.

check this link:http://www.cocos2d-iphone.org/forum/topic/21620

From this link,

I am guessing, in your game ,body is b2static body,What you can do is Move your sprite to center of the screen, with respect to that change the position of the corresponding body in tick method.

And you need to stop moving the sprite when it hits the center ball so stop moving corresponding sprite when it hits the center ball.

This may be the possible way if i understood your question.