Getting Actors to Orbit Each Other at Various Levels
Scone
Member Posts: 26
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!
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
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.
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 . . .
Click on the white actor:
http://www.mediafire.com/?njppj5yvcpb9ocd
...
http://www.mediafire.com/?92qe9pemu8icr7a
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!
Q: Why would you want to use %360 ? 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.
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 . . . .
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
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.
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.
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!
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.
http://www.mediafire.com/?wqiy5x44r5qlh82
http://www.mediafire.com/?isrsdax11f8aacx
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.
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.