Multiple sources of gravity?

covcommcovcomm Member Posts: 3
edited November -1 in Working with GS (Mac)
Hi,

I'm new here so bear with me if someone suggested this before...

I was wondering if it's possible to create actors with there own gravity, so in addition to the main scene gravity, a player can jump from platform to platform and walk underneath a floating platform, but if they jump too far, they fall all the way to the bottom of the level.

Of course this would go hand in hand with been able to use the accelerometer to change the games orientation from landscape to portrait (is this possible with gamesalad?) and being able to move the scenes gravity from down to up or anywhere you want it to go.

I think an 'attractor' is what I'm after.

Comments

  • scitunesscitunes Member, Sous Chef Posts: 4,047
    Don't use scene gravity. Gravity is just acceleration towards the center of the earth (scientifically speaking). From a GS standpoint it just means acceleration with a 270 angle. I now just put this into any actor I want to fall. To change the direction of gravity have an actor that is the "target." In real life the "target" that we are pulled toward is the earth. Not sure if what your actors are pulled toward is something visible, like a planet, or it is more obscure than that. Lets say you have creatures walking on a circular planet. Create the planet image and give that actor a circular collision shape. Create two integer game attributes (planetX and planetY) and constrain them to the X and Y position of the planet. Then in the creatures create a self attribute (angle) called GravityDirection. Constrain GravityDirection to VectorToAngle (self.position.X - game.planetX, self.position.Y - game.planetY). This gives you the angle between the creature and the center of the planet. Then in the creature have an ordinary acceleration, but put self.GravityDirection for the angle and set the speed to whatever feels right.

    So lets say you wanted it to depend on the orientation of the iphone. Do just like above but create an invisible actor instead of the planet. Same rules but make it invisible and put in the accelerometer rules as outlined in the wiki. Then when you tilt the phone objects will fall towards the tipping phone.
  • covcommcovcomm Member Posts: 3
    Ok, sorry I took so long to respond, but I got a chance to try it out today and I got weird results...

    First, the planet actors gravity for some reason isn't attracting my 'creature' actor, the creature goes straight upward!

    Second, if I temporarily remove the planet from my scene, my creature goes straight up again!

    Not exactly what I'm looking for but, at least this is a great way to get game gravity to move in the opposite direction.

    Here's what I got:

    Game attributes:
    planetX (integer)
    planetY (integer)

    Scene attributes:
    gravity = 0

    Planet attributes (prototype):
    Constrain Attribute game.planetX to self.positionX
    Constrain Attribute game.planetY to self.positionY

    Creature attributes (prototype) :
    GravityDirection (angle)

    Constrain Attribute: self.Gravity.Direction to vectorToangle( self.positionX - game.planetX, self.positionY - game.planetY)

    Accelerate:
    Direction: self.GravityDirection Relative to: actor
    acceleration: 100

    I think that's what you mentioned above, but it didn't work as planned.

    So my question is, how do make the planet the center of gravity, so that the creature falls to toward it?
  • scitunesscitunes Member, Sous Chef Posts: 4,047
    try relative to scene in the accelerate direction
  • covcommcovcomm Member Posts: 3
    Just tried it...no effect. My creature floats upward. Not sure why it ignores the planet or why it floats upward when the planet is not in the scene.
  • ORBZORBZ Member Posts: 1,304
    just use AccelerateToward behavior instead of Accelerate. Plug in game.planetX and game.planetY for the x and y params, set the RelativeTo parameter to scene.

    That way you don't need to use vectorToAngle.
Sign In or Register to comment.