How do I: Make a sprite circle another sprite?

Get help using Construct 2

» Wed Mar 15, 2017 2:13 am

Hey guys!

I am new to Construct 2, and I am building a platformer.

My question is: How do I make a sprite fly around another sprite? (For instance: to simulate a smaller sprite "moving/flying around" a larger sprite on its x-axis, and perhaps move between layers to simulate the effect of the smaller sprite moving behind the larger sprite) ...

This image illustrates my question:

Thanks in advantage and best regards!
- Jacob

---------------------------------------------------------------------------------------------------------------------------------------------------------------

Edit: Due to incapability in using the english language I changed the word "orbit" with "circle" in order to explain myself better.
Last edited by JacobBaekgaard on Wed Mar 15, 2017 5:58 pm, edited 1 time in total.
B
5
S
1
G
1
Posts: 3
Reputation: 831

» Wed Mar 15, 2017 9:21 am

Banned User
B
29
S
7
G
58
Posts: 1,229
Reputation: 34,910

» Wed Mar 15, 2017 6:12 pm

Hey, Lamar

I went to https://www.scirra.com/forum/viewtopic.php?f=159&t=185994&p=1093136&hilit=orbit#p1093136 and had a look, where I stumbled upon R0J0hound's solution.

R0J0hound wrote:"Universal gravitation" is the formula you'd want to look at to do the gravity force between two objects.
Force = G*mass1*mass2/distance^2
That's the magnitude of the force, the direction is toward each other.

Now an object will orbit another if it's velocity is perpendicular to the direction of the other object and it's speed is sqrt(massOther/distance).

Here's my test of it:
https://dl.dropboxusercontent.com/u/542 ... imple.capx

Now I haven't played solar but considering a good orbit just doesn't happen then I suspect that some additional force is used to steer the smaller objects to get in a good orbit.

After having a look at R0J0hound's capx file I tried making a new project myself to test the code, but I don't know how to make the same code with two different sprites (a smaller sprite and a larger sprite of different colors), as I am still new to Construct 2. Nor do I know how to make the smaller sprite circle the larger one as presented on the picture in the original post. In other words: It's quite complicated for me to understand R0J0hound's solution.

Any pointers or suggestions? Thanks in advantage
B
5
S
1
G
1
Posts: 3
Reputation: 831

» Wed Mar 15, 2017 6:16 pm

JacobBaekgaard wrote:

Hey, Lamar

I went to https://www.scirra.com/forum/viewtopic.php?f=159&t=185994&p=1093136&hilit=orbit#p1093136 and had a look, where I stumbled upon R0J0hound's solution.

R0J0hound wrote:"Universal gravitation" is the formula you'd want to look at to do the gravity force between two objects.
Force = G*mass1*mass2/distance^2
That's the magnitude of the force, the direction is toward each other.

Now an object will orbit another if it's velocity is perpendicular to the direction of the other object and it's speed is sqrt(massOther/distance).

Here's my test of it:
https://dl.dropboxusercontent.com/u/542 ... imple.capx

Now I haven't played solar but considering a good orbit just doesn't happen then I suspect that some additional force is used to steer the smaller objects to get in a good orbit.

After having a look at R0J0hound's capx file I tried making a new project myself to test the code, but I don't know how to make the same code with two different sprites (a smaller sprite and a larger sprite of different colors), as I am still new to Construct 2. Nor do I know how to make the smaller sprite circle the larger one as presented on the picture in the original post. In other words: It's quite complicated for me to understand R0J0hound's solution.

Any pointers or suggestions? Thanks in advantage

Not my CAPX so let's jingle @R0J0hound and see if he can help.
Banned User
B
29
S
7
G
58
Posts: 1,229
Reputation: 34,910

» Wed Mar 15, 2017 7:02 pm

B
176
S
50
G
200
Posts: 8,632
Reputation: 124,565

» Wed Mar 15, 2017 7:23 pm

newt wrote:https://www.dropbox.com/s/ir5v6fzg54hvg8p/orbit.capx?dl=0

Thank you SO MUCH, newt! That is exactly what I was looking for
B
5
S
1
G
1
Posts: 3
Reputation: 831