Make the player orbit around a center point?

0 favourites
  • 8 posts
From the Asset Store
Connect the dots in the correct order and draw happy animals!
  • 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?

  • 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.

    dl.dropbox.com/u/142115313/SimpleSpace/index.html

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Here is an example that helped me out with a similar question.

    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.

  • 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 ;)

  • Matt75: How do you 'pin' an object to another object?

  • Yttermayn

    Don't forget about the manual and tutorials :)

    Manual..

    scirra.com/manual/99/pin

    Tutorial..

    scirra.com/tutorials/243/building-a-platform-game-a-beginners-guide/page-2

  • 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..

  • I ended up trying out a physics distance joint, but it needs some tweaking. Thanks for all the replies!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)