I have two circles, the smaller circle of which revolves around the other bigger circle (simulating an orbit). When the user clicks with the mouse, there is an impulse applied to the small circle which jumps. I want that if the smaller circle lands back on the bigger circle, it goes back into orbit again and its speed and direction ( clockwise/anticlockwise) change depending on the point of impact. I am using the physics behavior but there are a lot of irregularities. Can someone suggest a way to do this? Many thanks.
Maybe this will help:
https://www.scirra.com/tutorials/273/ho ... platformer
This seems good when using the platform behavior but I don't want to use it as physics and platform behavior working together can cause some issues. Also, it seems a very unnecessary route to take. As of now on collision I am applying a force on the small ball towards the center of the bigger ball. I have disabled all physical properties of the bigger ball and the ball as of now stays in motion depending on how it lands. But Its still not clean. I will work on it and post some better results if I can find it. It should be very simple but I seem to be missing something
Develop games in your browser. Powerful, performant & highly capable.
For orbits with physics you can do it using equations of actual orbiting. Some info and capx on it here:
Basically you can do the gravity force with "newton's law of universal gravitation" and set the orbit by setting the velocity to a calculated "mean orbital speed" and set the direction to be perpendicular to the direction from the moon to the planet.
Calculating the impulse to change directions may be doable, just your standard algebra problem, but it's probably simpler to just set the velocity directly.
Thank you. Wouldn't this be too heavy on memory? considering it updates forces every tick and in case of of multiple objects wouldn't it get too high?
You mean heavy on cpu usage? Test it and see how heavy it is. Setting the force is basically just setting a number and has a negligible performance impact.