Author Topic: Reversing Gravity  (Read 1198 times)

epic428

  • Member
  • **
  • Posts: 10
  • Karma: +0/-0
    • View Profile
    • Epic Tech World
Reversing Gravity
« on: Wed, Jul 7, 2010 »
Code: [Select]
public function Player()
{
super(50, 50, ImgPlayer);
maxVelocity.y = -500;
this.acceleration.y = -450;
}

override public function update():void
{
velocity.x = 0;
velocity.y = 0;

if (FlxG.keys.LEFT)
{
velocity.x = -250
}
else if (FlxG.keys.RIGHT)
{
velocity.x = 250
}
if (FlxG.keys.justPressed("UP") && velocity.y == 0)
{
velocity.y = 850
}

I am having some trouble reversing gravity so that the game is upside-down. These are just some of the #'s I have tried and it is not working as smoothly as it does normal gravity. Any ideas or suggestions to improve on this would be greatly appreciated. Above is the necessary code. My main issue with the gravity is jumping is not what is so smooth. well that and the character is constantly fidgeting while standing still.
« Last Edit: Wed, Jul 7, 2010 by epic428 »

initials

  • Contributor
  • ****
  • Posts: 378
  • Karma: +0/-0
  • Initials
    • View Profile
    • Initials Blog. Code and other things.
Re: Reversing Gravity
« Reply #1 on: Wed, Sep 8, 2010 »
It's as simple as reversing acceleration.

Code: [Select]
acceleration.y = -acceleration.y;
You may need to add
Code: [Select]
this. in front depending on where you place the code, but the above worked for me in the Mode demo.
Initials: Super Lemonade Factory, Super Lemonade Factory Part Two, Above The Clouds, Revvolvver, Four Chambers of the Human Heart

Loupax

  • Member
  • **
  • Posts: 81
  • Karma: +0/-0
    • View Profile
Re: Reversing Gravity
« Reply #2 on: Wed, Sep 8, 2010 »
or even quicker:

function gravitySwap():void{
this.acceleration.y *= -1;
}
As the size of an explosion increases, the number of social situations it is incapable of solving approaches zero.
--Vaarzuvius
My blog!

initials

  • Contributor
  • ****
  • Posts: 378
  • Karma: +0/-0
  • Initials
    • View Profile
    • Initials Blog. Code and other things.
Re: Reversing Gravity
« Reply #3 on: Wed, Sep 8, 2010 »
Thanks! I'm going to use that piece of code if you don't mind.
I'm working on a mod to Mode that uses gravity switches. Not an entirely original idea but it's just something to get my head around Flixel
Initials: Super Lemonade Factory, Super Lemonade Factory Part Two, Above The Clouds, Revvolvver, Four Chambers of the Human Heart

Loupax

  • Member
  • **
  • Posts: 81
  • Karma: +0/-0
    • View Profile
Re: Reversing Gravity
« Reply #4 on: Wed, Sep 8, 2010 »
!!!
This code is copyrighted material!
(Joking :P)
As the size of an explosion increases, the number of social situations it is incapable of solving approaches zero.
--Vaarzuvius
My blog!