Rotate object + move to object position

For questions about using Classic.

Post » Thu Aug 18, 2011 3:01 pm

Hi i need help, i want to make behavior as on picture:

One object i copy to 10 pieces. All object have to rotate around planet and move to planet position. I do not know hot to. pls help me :/
B
24
S
4
G
2
Posts: 318
Reputation: 2,446

Post » Thu Aug 18, 2011 4:05 pm

Here you are:
http://www.mediafire.com/file/74rcbjcsv1b9d9a/planetattraction.cap

For tasks like this, sin and cos are your friends. The principle is as follows:
1) Calculate the distance from the objects to the planet on creation (posRadius)
2) Calculate the angle between the objects and the planet on creation (posAngle)
3) On every tick
   - rotate planet by 'rotationspeed'
   - rotate 'posAngle' by 'rotationspeed'
   - set object's x to planet.X + cos('posAngle') * 'posRadius'
   - set object's y to planet.Y + sin('posAngle') * 'posRadius'
   - reduce 'posRadius'

You can reduce 'posRadius' with a fixed value. I reduce it based on the object's size (smaller ones get attracted faster than bigger ones). If you don't want that behavior, just set object's 'factor' to 1 in event 2:
replace
-> attracted: Set 'factor' to .Width / 32 - 0.5
with
-> attracted: Set 'factor' to 1

Set the strength of the planet's attraction with the pv 'force'.
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Thu Aug 18, 2011 4:06 pm

There is a plugin around on the forums called Orbiter, if you give those red circles the behavior and then decrease the radius of their orbit around the planet, it will have the effect you want.

Try using the forum search to find it since it was released a long time ago now.
"Construct 4 lets YOU make advanced games! (maybe)" Construct Classic - Examples Kit
B
86
S
28
G
13
Posts: 2,092
Reputation: 15,009

Post » Thu Aug 18, 2011 4:12 pm

How I'd love people to more often use events. It would help so much understanding what is going on with the objects :)
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Thu Aug 18, 2011 4:38 pm

[QUOTE=tulamide] How I'd love people to more often use events. It would help so much understanding what is going on with the objects :)[/QUOTE]

True, but plugins run raw C++.
"Construct 4 lets YOU make advanced games! (maybe)" Construct Classic - Examples Kit
B
86
S
28
G
13
Posts: 2,092
Reputation: 15,009

Post » Thu Aug 18, 2011 5:44 pm

Thx a lot but i need to set my positions, but i try it from this .cap when i will have got a problem with it i will write again ;)
B
24
S
4
G
2
Posts: 318
Reputation: 2,446

Post » Thu Aug 18, 2011 6:25 pm

I know for a fact that the Orbiter behaviour is perfect for this sort of task. I had a plane orbited by several evenly spaced thingies no problem. So just look into it.
B
19
S
6
G
6
Posts: 1,101
Reputation: 5,646

Post » Thu Aug 18, 2011 6:52 pm

No orbiter does not work right with this all things ;)
B
24
S
4
G
2
Posts: 318
Reputation: 2,446

Post » Thu Aug 18, 2011 8:09 pm

Well, in this case I use a for each loop to give the orbiting objects random behaviours - if you want specific behaviours you'll have to adjust them by hand for each object, but this seems to do pretty much what you explained in the initial post.

Grab the cap here (needs the Orbiter behaviour).
B
19
S
6
G
6
Posts: 1,101
Reputation: 5,646

Post » Thu Aug 18, 2011 9:55 pm

Or you just do it with the two events and without the need of a behavior as I showed in my cap in my first post
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Next

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 5 guests