Make the player orbit around a center point?

Get help using Construct 2

Post » Sun Dec 30, 2012 4:06 am

I want an objective based asteroid type game with a space station in the middle and the player orbiting around the ship. The player would point to where the mouse is but I want it to circle the station on a fixed orbit, but have no idea how to do this or if it's even possible. I don't want it doubling back on itself if the mouse is in the center of the station, so the ship shouldn't pivot on it's center. Any ideas?
B
6
Posts: 90
Reputation: 690

Post » Mon Feb 04, 2013 3:15 am

I figured out how to do this using the circle plot formula.

NewX = OrbitDistance * cos(DegreesAngle) + OrbitCenterX
and
NewY = OrbitDistance * sin(DegreesAngle) + OrbitCenterY

Where NewX and NewY are the X,Y coordinates of where your ship is going to be, DegreesAngle is what angle off of the space station you're calculating for, and OrbitCenterX and OrbitCenterY are the center coordinates of your space station, aka. the thing your ship is orbiting.
If you keep incrementing DegreesAngle every tick, and assigning your shiup objects X and Y position to NewX and NewY, it will orbit in a circle around the space station at a range (radius) of OrbitDistance.
Playing with how much DegreesAngle is incremented will adjust the speed, and you can even decrement it into the negatives to reverse the direction or orbit.
You should probably put in a conditional statement that makes DegreesAngle wrap around from 360 to 0 or vise-versa depending on the direction of orbit. Otherwise, when the variable you are storing DegreesAngle in reaches its maximum value and wraps around, the ship will 'jump' to a different position in it's orbit suddenly. This might never come up depending on what size variables C2 uses. I don't know, I'm still learning the system.
Anyways, here is an example from something I'm working on.

https://dl.dropbox.com/u/142115313/SimpleSpace/index.html
B
11
S
4
G
1
Posts: 159
Reputation: 1,803

Post » Mon Feb 04, 2013 7:40 am

Here is an example that helped me out with a similar question.

https://dl.dropbox.com/u/139739932/test/RotateAroundObject.capx

I can't find the thread to which it belongs atm because it was not my question and i didn't reply to it. Hope it helps.
B
12
S
2
G
3
Posts: 59
Reputation: 2,628

Post » Mon Feb 04, 2013 12:25 pm


pin your player to an object - the object can be rotated, and the player will now rotate around that object - its a simple solution, might not be perfect ;)
B
6
G
2
Posts: 37
Reputation: 1,499

Post » Mon Feb 04, 2013 6:47 pm

Matt75: How do you 'pin' an object to another object?
B
11
S
4
G
1
Posts: 159
Reputation: 1,803

Post » Mon Feb 04, 2013 7:16 pm

@ Yttermayn
Don't forget about the manual and tutorials :)

Manual..
https://www.scirra.com/manual/99/pin

Tutorial..
http://www.scirra.com/tutorials/243/building-a-platform-game-a-beginners-guide/page-2
B
5
S
1
G
1
Posts: 12
Reputation: 899

Post » Mon Feb 04, 2013 8:37 pm


Pin is a behaviour - add this to your player.

Rotate is another behaviour - create another sprite (acting as an origin) + add this behaviour.

in your event sheet add an event - System->on start of layout..
as the action for that event - pin player to origin sprite..

run it, and your player is now rotating with the origin sprite, as the origin sprite rotates..

matt752013-02-04 20:39:37
B
6
G
2
Posts: 37
Reputation: 1,499

Post » Tue Feb 05, 2013 3:46 am

I ended up trying out a physics distance joint, but it needs some tweaking. Thanks for all the replies!
B
6
Posts: 90
Reputation: 690


Return to How do I....?

Who is online

Users browsing this forum: Mohicano and 24 guests