How do I implement orbits w/o physics behavior?

Get help using Construct 2

Post » Thu Mar 06, 2014 8:29 pm

I've realized the physics behavior is really slowing my game down so I'd like to not use it. I really only need it to get one sprite to orbit one or more other sprites. Is there a way to do this?
B
10
S
4
G
3
Posts: 103
Reputation: 2,984

Post » Thu Mar 06, 2014 11:28 pm

Yes there is.

just pin the object to rotate to an invisible sprite with the Rotate behaviour.

Attached is the capx. hope it helps. :)
You do not have the required permissions to view the files attached to this post.
B
72
S
25
G
9
Posts: 383
Reputation: 10,661

Post » Fri Mar 07, 2014 12:03 am

Thanks dude. This method may work.

I want to have a character that can instantly switch from orbiting a planet to freely floating. I want the character's angle and velocity to factor into how it orbits a planet instead of simply orbiting at a predetermined speed and distance.

EDIT: Maybe this won't work. If the character is floating towards a planet, I don't want it to start spinning around that planet when I active orbit. I'd like the character to go 'through' the planet and back and forth.
B
10
S
4
G
3
Posts: 103
Reputation: 2,984

Post » Sun Apr 13, 2014 7:39 am

I to am trying to make a object orbit and the pin and rotate method while easy is a little jerky and I would like smooth motions. I am using some Trigonometry but I seem to be having some issues with my math.

Each tick move at angle Tan((distance(Star.X, Moon.Y, Star.X, Star.Y))/(distance(Moon.X, Star.Y, Star.X, Star.Y)))

its 3:30AM and it looks right but idk as Moon.X approaches 0 Moon.Y approaches 1. Giving if the planet was one unit away.

I tried putting in just tan(60) but my planet keeps moving at 0*. Could tan() be bugged?
"Were all mad here. I'm mad, your mad." "How do you know I'm mad?" Asked Alice. "You must be" Said the Cheshire Cat. "Or you wouldn't have come here"-Lewis Carroll: Adventures In Wonderland
B
7
S
2
Posts: 113
Reputation: 1,245

Post » Sun Apr 13, 2014 2:53 pm

Old school Trig: Make invisible object and have it rotate every tick. Make actions for the orbiting object........set x to invisible object.x+(cos(invisible_object.angle)*100) and set y to invisible object.y + (sin(invisible_object.angle)*100) . You could replace the 100 with whatever distance you want or use variable's that change . This also works with spiraling orbits with a few additions to code . Tan is not relevant in this situation .
What I know would fill a Book , what I don't know would fill a Library
B
37
S
12
G
29
Posts: 331
Reputation: 16,499

Post » Thu Apr 17, 2014 11:24 pm

@CrazyVulcan If you get that going, would you post a capx?

@granpa What additions would you make for a spiraling orbit?
B
10
S
4
G
3
Posts: 103
Reputation: 2,984

Post » Fri Apr 18, 2014 7:09 pm

Here is an example of an orbit based on Newton's law of universal gravitation.
https://dl.dropboxusercontent.com/u/542 ... orbit.capx

Basically it means that the velocity of the moon is taken into consideration.
B
91
S
31
G
103
Posts: 5,234
Reputation: 67,754

Post » Fri Apr 18, 2014 11:59 pm

@R0J0hound Thanks! Do you happen to know if this could work with two or more planets (with alterations)?

EDIT: Also, I would like to turn to incorporate the bullet behavior into the moons so they bounce off solids. How would I do this?
B
10
S
4
G
3
Posts: 103
Reputation: 2,984

Post » Sat Apr 19, 2014 3:25 am

For more planets change the "every tick" to "for each planet" and add another "every tick" event below and move the "set position" action to that.

To make it work with the bullet behavior you'll have to covert the speed and angle of motion to vx and vy in an "every tick" before the events and back at the end of the events. Also the "set position" can be removed and the overlap and bounce event should be either before or after the events.

Here are the conversion formulas:
Vx=speed*cos(angle of motion)
Vy=speed*sin(angle of motion)

And

Speed=distance(0,0,vx,vy)
Angle of motion=angle(0,0,vx,vy)
B
91
S
31
G
103
Posts: 5,234
Reputation: 67,754

Post » Sat Apr 19, 2014 4:48 pm

@bachrock I did not get my idea to work but I did come up with a number of ways to get it to work, including the Pin&Rotate method. Granpa's steps work great and I also found for cool elliptical orbits have a rotating object that your planet is pined to and have it move every tick so far. I did not like this last one as it was not very precises but it did look cool. I also made a invisible circle sprite with two refpoints and had the sun and planet on each end and just had the circle rotate, which was time consuming.

The Pin&Rotate is the best the resin I had trouble with it was because my sprites were too small. so it was jumping form pixel to pixel. I just scaled it up a bit and it works beautifully.
"Were all mad here. I'm mad, your mad." "How do you know I'm mad?" Asked Alice. "You must be" Said the Cheshire Cat. "Or you wouldn't have come here"-Lewis Carroll: Adventures In Wonderland
B
7
S
2
Posts: 113
Reputation: 1,245

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 4 guests