How do I keep a player "on rails"?

0 favourites
From the Asset Store
Basic Rounded Vector Geometry Player Design with Glow for 3 player games
  • I'd like to create a game in which the player object can be touched and dragged around a circle, but not off-circle. So, effectively, the circle acts as a "rail" that the player is locked to and can navigate freely, but only left or right around the outline.

    Can anyone offer any advice on how to make something like this work?

  • There's a few ways of handling this depending on the specific behaviour you're after. Do you want the player to be able to move freely inside the circle, or only around the outside of the circle?

    If the player can move freely within the circle its quite simple, use this event, just make sure to doublecheck the image point of the player character and collision polygon of the circle.

    http://imgur.com/vDeDxdQ

    If you want to have the player only able to move around the outer edge, I would create a second smaller and invisible circle sprite, and place it inside the first circle, again making sure the collision polygon fits, and edit the event like this :

    http://imgur.com/FF7JADV

    Hope that helps!

    EDIT : For some odd reason the forum doesn't like my images, put links to them in instead.

  • you want the player to follow the mouse and also stay in the circle edges?? that example above only allows you to move the player when the mouse is touching the circle, but you could do it easy , by creating a more complex edge detection with position and distance of the character based on bbox ,left right top down, of the circle, and then you could click anywhere on screen if you want to.

  • I want to have multiple players able to move their own objects along the rail (on a touch screen device), so I won't be using the mouse object.

    I also want to have the object actually move along with the player's finger, perhaps with a bit of leeway so it can continue moving even if they get a little ahead of the object itself (I could do an "Is touching object", but the movement stops immediately if the player isn't right on top of it the whole time).

    I think your examples with the two circles is pretty helpful if I make the size difference very minimal (I really want zero forward or backward wiggle room...only sliding left or right down the "rail"),

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I would go for something like this:

    https://dl.dropboxusercontent.com/u/485 ... ircle.capx

  • I would go for something like this:

    This is exactly what I was looking for! Thank you!

  • I would go for something like this:

    Wait, I lied! There's still an issue with this one, but hopefully you can help me figure it out.

    When I try this on a touch device, I can move one circle fine, but touching the second one immediately jumps it to the position of the first touch. I'd like to link the separate instances of these sprites to whatever touchID touched them last, so multiple players can move multiple sprites at the same time independently.

  • Actually im wrong, still doing the jumping thing you talking about, tried with a tx ty but cant really figure it out now gluck

  • Ah, ok.. can't test on mobile now, but my implementation of the touchID leaves something to be desired..

    try this:

    https://dl.dropboxusercontent.com/u/485 ... uchID.capx

  • Ah, ok.. can't test on mobile now, but my implementation of the touchID leaves something to be desired..

    try this:

    Still behaving the same. I tried doing something similar with picking events but it also didn't seem to work.

  • Sorry, another try.. <img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile">

    https://dl.dropboxusercontent.com/u/485 ... touch.capx

  • Sorry, another try..

    That's it! It works perfectly. Thank you so much for your help.

    Bonus question: If I were to change the shape of the circle (perhaps to make it more of an oval), how would I change the code? It looks like I'd maybe have to change that "move 0.5*sprite.width pixels" bit?

  • Oval would be pretty hard, haha..

    in this particular case 0.5*sprite.width is the radius of the circle, an oval is a bit harder to calculate..

    I'm not really that good at math..

  • Yeah, I'm no good at math, either, ha.

    What if it was more of a pill shape with multiple sprites? Like, two circles for the sides (but only half is used) and two lines in the center connecting them? It doesn't need to be EXACTLY an oval, but my thinking is that I'd like the sprites to rotate around as much of a widescreen window as they can. Something with the sprites changing their movement behavior when they collide with a different part of the pill?

    I guess an RC racetrack (in the simplest configuration) would be a better visual analogy?

  • Yeah, a pill- shape could be done..

    It would consist of checking the x coordinate of the touch and using an angle of 90/270 degrees when in the straight part and the angle towards touch from the circle center when in the half circle part..

    Even nicer would be to give the pil harmonica-movement, so it goes from pill-shaped to circle and back.. :p

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