Getting Actors to Orbit Each Other at Various Levels

SconeScone Member Posts: 26
edited February 2013 in Working with GS (PC)
Hey guys, Scone here with another complicated question! So in my game, there will be various actors moving around; one will be control by the player via clicking/tapping the screen, and the others will be NPCs which move around the environment at random. I'm trying to implement a new mechanic, however, that I am having a lot of difficulty with. Essentially, I want to make it so that the NPC actor with orbit the player actor if they are within a certain distance, and for there to be multiple levels/distances of orbiting. To make this a bit more clear, I'll lay out what an encounter would look like:

1. NPC 1 is floating around, and the player decides to go orbit with it.
2. Player Actor is moved within...let's say 300 pixels...of NPC 1, and they begin to orbit each other. Think of it like them locking onto each other as a pair.
3. The NPC Actor is now orbiting the Player actor; it could also be interesting if they orbiting each other, so to speak (as in spin in a circle).
4. The player wants to decrease the orbit distance to the next level of 200 pixels.
5. To do this, they flick their actor towards the NPC (as in flicking/dragging on the screen).
6. The Player Disk moves to the next level of orbit.
7. The Player decides to get out of orbit, so they must flick their character back to the 300 level, and then flick again to remove their character from the NPC.

I don't know if GameSalad has a rule such that the Player Actor must receive only a certain amount of force or they shoot past the NPC, but even if there is I don't need that for now. Essentially, once the player is locked in at that initial level, a flick inwards automatically moves it to the next level.

I realize this is probably a rather complicated mechanic, but I know you're a smart bunch of designers! If you guys need any more info to make this question easier to answer, please let me know. Thank you for your time!

Comments

  • SconeScone Member Posts: 26
    I try to avoid doing this when possible, but because trying to work out a solution to this is really important (and I'm still having difficulty with it), I'm going to bump this up. Sorry, guys!
  • SocksSocks London, UK.Member Posts: 12,822
    I try to avoid doing this when possible, but because trying to work out a solution to this is really important (and I'm still having difficulty with it), I'm going to bump this up. Sorry, guys!
    Maybe you could simplify your question.
  • SconeScone Member Posts: 26
    I'll do my best, Socks! I did find some threads on orbiting actors around each other, so that I can get into place. What I'd like to happen is for players to be able to place their character at different orbiting distances from other actors (400 pixels, 300 pixels, and 200 pixels for example). So the two questions I'd have would be:

    1. Is there a way to allow players to engage or disengage the orbiting function (so its not a constant orbit, but based on proximity).

    2. Is there a way to allow players, once they are in orbit, to move closer to whatever they are orbiting.

    I hope that's a bit more clear.
  • SocksSocks London, UK.Member Posts: 12,822
    edited February 2013
    1. Is there a way to allow players to engage or disengage the orbiting function (so its not a constant orbit, but based on proximity).

    Yes, just check the distance using magnitude.

    2. Is there a way to allow players, once they are in orbit, to move closer to whatever they are orbiting.

    Sure, there are numerous ways, run out of fuel, pulled in by gravity, after a certain period of time, maybe touch the orbiting actor . . . etc etc . . . whatever you want to trigger a rule that lowers it's orbit.

    Let me try one out . . . . I'll be back . . .
  • SocksSocks London, UK.Member Posts: 12,822
    edited February 2013
    2. Is there a way to allow players, once they are in orbit, to move closer to whatever they are orbiting.

    Click on the white actor:

    http://www.mediafire.com/?njppj5yvcpb9ocd



    ...
  • SocksSocks London, UK.Member Posts: 12,822
    + a wobbly orbit, not sure why anyone would want this, but it shows you what can be done . . . .

    http://www.mediafire.com/?92qe9pemu8icr7a
  • SconeScone Member Posts: 26
    Thank you, Socks! I'll play around with those today and report back!
  • SconeScone Member Posts: 26
    So as I Said before, there are some functions that I don't quite get. When you used Constrain Attribute for B1 (the orbiting actor), your equation was:

    self.ORBIT DISTANCE*sin(game.time*50)+512; cos for y.

    When I was looking at some videos last night, I noticed that a different equation was used, looking something like:

    100*sin(self.Time*50%360)+game.added attribute x; the added attribute would be named as the x position for the object being orbited, and there would be another attribute added for its y.

    Essentially, my questions are as follows:

    -Why did you use that self.ORBIT DISTANCE as opposed to a flat number?
    -Why use game.time instead of self.time?
    -Why did you not use that %360?
    -Why use that flat 512 as opposed to those two added attributes?

    Looking at what else is in there, I'm guessing the answer to the first question was because of the interpolate function in order to move the actors closer.

    Thank you for your time!
  • SocksSocks London, UK.Member Posts: 12,822
    edited February 2013
    -Why did you use that self.ORBIT DISTANCE as opposed to a flat number?
    Because we want the orbit distance to change when we click on it - so I made it a variable value, something we could alter when we wanted.
    Why use game.time instead of self.time?
    No particular reason, I just threw the thing together, didn't really plan it out, just clicked on the first timer I saw . . . . game.timer, scene.timer or self.timer, use whichever timer works best for your game.
    Why did you not use that %360?
    Interrogative-sentence-containing-negation alert - does not compute. 8-X :)

    Q: Why would you want to use %360 ?
    Why use that flat 512 as opposed to those two added attributes?
    You've lost me a bit here, I'm not sure what the question means, what two added attributes ?
    512 is the centre of an iPad screen, you can change this value to whatever you want.
    Change stuff, see what happens. :)
  • SconeScone Member Posts: 26
    I got the overall orbiting mechanic to work, and now it only starts to activate once you get to a certain distance. The issue I'm trying to work out, though, is that the NPC object instantly shoots to some point in the orbiting circle, as opposed to smoothing into position (meaning that it always just kind of teleports into the bottom right corner of the "circle" and then orbits, as opposed to beginning where it enters that distance). Do you have any ideas for how to fix that?
  • SocksSocks London, UK.Member Posts: 12,822
    I got the overall orbiting mechanic to work, and now it only starts to activate once you get to a certain distance. The issue I'm trying to work out, though, is that the NPC object instantly shoots to some point in the orbiting circle, as opposed to smoothing into position (meaning that it always just kind of teleports into the bottom right corner of the "circle" and then orbits, as opposed to beginning where it enters that distance). Do you have any ideas for how to fix that?
    Yeah, the position in the orbit is defined by whatever is in the brackets after sin and cos, in my example I used 'time' so as the app plays the time goes up so the actor moves around the orbit, but you can use anything you want here, so . . .

    You can work out where your actor enters the orbit using the vector to angle thingy, so let's say we work out it enters orbit at 178.4 degrees, we then simply need the thing in the brackets after sin and cos to start at 178.4.

    That's the basic idea . . . .

  • SconeScone Member Posts: 26
    I tried out what you suggested, and it causes the NPC character to kind of shoot around. I'm not sure if I entered it incorrectly, but what I essentially did was:

    1. Created an attribute on the NPC character (npcangle), and constrained that to vectorToAngle(game.Player's x-self.positionx, game.Player's y-self.positiony).

    2. I put that into the constrain attribute rules for the orbit, which now look like this:

    self.orbitdistance*cos(self.npcangle1*50)+game.Player's x

    self.orbitdistance*sin(self.npcangle1*50)+game.Player's y
  • SocksSocks London, UK.Member Posts: 12,822
    edited February 2013
    Here's a very quick idea for you - sorry the code is very messy, but the method works:

    http://www.mediafire.com/?eat340zgba24pou

    Drag the white actor towards the outer orbit.

    Clicking the actor once it is in orbit sends it to a lower orbit.
  • SconeScone Member Posts: 26
    Socks, this is a great idea! It introduces some really interesting functionality as well. I noticed that you had the original satellite change its color.alpha to 0, but am I correct in saying the game would need more processing power to do this than if I simply destroyed it? My assumption is that the actor is still present, even with the alpha set to 0.
  • SocksSocks London, UK.Member Posts: 12,822
    Socks, this is a great idea! It introduces some really interesting functionality as well. I noticed that you had the original satellite change its color.alpha to 0, but am I correct in saying the game would need more processing power to do this than if I simply destroyed it? My assumption is that the actor is still present, even with the alpha set to 0.
    Yes, the actor is still present (just invisible), like I say it's a very quick and messy piece of code just to illustrate the idea - I'm sure you could use it as a starting point and make the code a little more elegant.

    The angle-of-contact is calculated from the yellow centre to the satellite - if you destroy the original satellite this value jumps to 0 - and the angle of contact gets screwed up.

    I'm sure there is a better way of doing this, but this is the basic idea.
  • SconeScone Member Posts: 26
    edited February 2013
    I played around with it, and I can see what you say. If anything, I could put in a timer so that the first actor disappears and then is destroyed a few seconds later.

    EDIT: I notice that you had, as part of the function constraining the angle of contact, a variable called scene.background.satellite.position.x--how do I access that variable? I can't find it.

    EDIT 2: Never mind! I found it!
  • SconeScone Member Posts: 26
    As of now, I do need to find a way to destroy the actor without it screwing up the angle of contact. Because my main actor moves around, the problem I ran into was that the invisible main actor would occasionally bump the circles a second time and spawn another actor.
  • SocksSocks London, UK.Member Posts: 12,822
    I played around with it, and I can see what you say. If anything, I could put in a timer so that the first actor disappears and then is destroyed a few seconds later.
    If you do this then the offset (the attribute called 'angle-of-contact') will jump to 0 when the first satellite is destroyed - which will make the replacement satellite suddenly jump to a new position (it's orbit minus the offset).


  • SocksSocks London, UK.Member Posts: 12,822
    edited February 2013
    As of now, I do need to find a way to destroy the actor without it screwing up the angle of contact. Because my main actor moves around, the problem I ran into was that the invisible main actor would occasionally bump the circles a second time and spawn another actor.
    Yeah I noticed that too ! : ) If you hold the satellite - contact the circle - but don't let go - then drag the satellite away from the circle and keep moving it in and out you can place lots of little satellites into orbit.

    I've just thought of a solution - I'll make a quick project and post it here - but basically we just need to copy the angle-of-contact value into another attribute to save it - so when we destroy the original satellite (and thus suddenly change it's value to 0) it won't effect our orbiting replacement satellite as this will be using this new attribute for it's offset value.
  • SocksSocks London, UK.Member Posts: 12,822
    Here you go . . . first actor is now destroyed, but first we record the angle-of-contact value into another attribute.

    http://www.mediafire.com/?wqiy5x44r5qlh82
  • SocksSocks London, UK.Member Posts: 12,822
    Version with an idea for a softer pull into the gravity - rather than a hard 'grab'.

    http://www.mediafire.com/?isrsdax11f8aacx
  • SconeScone Member Posts: 26
    Awesome! What would I ever do without you, Socks?
  • SocksSocks London, UK.Member Posts: 12,822
    edited February 2013
    Awesome! What would I ever do without you, Socks?
    Travel in straight lines ?

    Like I say, all this code is a bit thrown together, but now the basic idea works you might want to go in and clean it up or redesign it - for example the interpolate which gives us the softer gravity pull (rather than the snap into position of the constrain) is a little glitchy if you go mad and swing your actor in and out of the circle (the thing it collides with) - not sure why, probably something obvious I've overlooked.
  • SconeScone Member Posts: 26
    For the time being, I'm having the NPC characters use a randomized movement, so it's more about moving the Player actor into range of the NPC's. At some point, I'll need to work out how to make sure there aren't multiple orbits going on at once (probably just create some game attribute, set it to 1 when in orbit with something, and you can't orbit with Player actor if attribute is >=1).
  • cucurbitcucurbit Member Posts: 68
    edited April 2013
    @Socks

    That is wonderful job here. I made some changes to the file you shared and have got some questions, if you don't mind.

    I've made it in different way and it works:

    My planet is at the center of the ipad, so I've got:

    If collides, interpolate (ease in/out) to
    150*sin( self.Time *100)+512
    150*cos( self.Time *100)+384

    and if x=150*sin( self.Time *100)+512 then constrain

    it works just fine, but this is really not what I have in mind. I wanted to make it quite different: for example, there is an actor who constantly goes right, when it is far from the planet that it will not be pulled so strongly, so it could go further and making just a little arc; so it doesn't always pull the player to the planet, it sometimes simply change its direction.

    Have you got any idea how to achieve it?

    If there is any possibility if I can return the favour then it would be even better. I can offer my services at photoshop&illustrator.


Sign In or Register to comment.