how to Fly?

Hi, i wanted to know how i can take some gravity down so my characters can fly.

Go to Properties/World (you must be in the Blender Game (not Blender Render)) there you find gravity. Turn it to 0.000 and you can fly!

Or use a property, local object or global variable doesn’t matter. We’ll call it flying. Now we code so when flying == True we set the objects linear velocity to greater than the opposite of your gravity which is default -9.8 on the global Z axis.

import bge
l = bge.logic
cont = l. getCurrentController
own = cont.owner
l.flying = False

def Fly():
      if own['flying'] == True:
          xspeed, yspeed, zspeed = own.getLinearVelocity(True)
          own.setLinearVelocity((xspeed,yspeed, 15),True)

Name this script

Make a boolean property on the object called flying set it to false. Or set it to true to see it working instantly.

Now attach this to an Always sensor, True Pulse and a python module controller set to player_fly.Fly

Then make a keyboard sensor set to some key with with true pulse, frequency 100 and Tap mode then add an AND controller and a property toggle set to your flying toggle.