Disabling Gravity in a Bullet?

Usually, when I want to fire a bullet, I just add it into the scene and then use the .applyForce command to fire it. However, to use .applyForce, the object has to be dynamic, which causes it to be affected by gravity. I’m looking for a way to fire a bullet where it will fly perfectly straight without being affected by gravity at all.

Thanks in advance for anyone’s help.

apply a contraire gravity to the bullet should work

own.applyForce((0, 0, 9.8), 0)

Add a counterforce against the gravity.

You can do that as MacoIT suggest or much simpler by applying following logic to the bullet.

Always sensor (No Pulses) -> OR -> MotionActuator Force: (0, 0, 9.8) Non-Local

Be aware that real bullets are affected by the gravity :wink:

I had tried that before, but it seems that since the .applyForce command doesn’t apply constant force, the bullet will eventually begin to dip again.

Your second option worked perfectly! Now, why would you use an OR controller here? For the most part, the only controllers I ever use are AND and Python.

Also, my bullet isn’t really intended to act like a true bullet would. :wink:

Actually I believe bullet applies 9.81 rather than 9.8 for gravity

The gravity is set at the scene tab. The default is 9.80.

@DarkFire7: Good observation.
If you only have one sensor AND and OR act the same. So it does not matter which one to use. I just want to show there is more than AND ;).

In some situations I prefer the OR as it allows to easily add “test” events to see if an Actuator does what you want. (e.g. triggering an action via keyboard sensor). The OR does not force you to un-connect the original sensor as the AND controller does.

The AND is the “traditional” controller as it was the default controller in pre-2.5 (the one after clicking “add controller”).

Or make it rigid body and under physics options disable rotations and Z axis, so it wont fall.

So, let me see if I understand the difference between AND and OR controllers: (I’m getting this off the user manual, so I just want to make sure my understanding is correct) for AND, all of the sensors attached to it have to be positive in order for it to send a positive signal. For OR, any of the sensors attached can be positive in order for it to send a positive signal. Is this correct?

I think I am just going to use Monster’s solution for disabling the gravity. Thank you though for the input.

Yes, this is correct.

You can read more about sensors in: Sensors - A Word on Pulses.

Would it work instead of adding a force to counteract gravity to just set linear velocity to 0 on z axis?


bullet.setLinearVelocity(bullet.getLinearVelocity()[0], bullet.getLinearVelocity()[1], 0)

Would that work?

No, because after clearing the velocity you still get the gravity applied.

This let you object slowly move to the ground. The falling speed does not sum up to form the known acceleration curve. It falls with a constant speed. The speed is the fall speed after 1 frame = 1s/60.

I think this side effect let some people think the gravity is higher in bullet than the configured 9.80.

Alright, thank you so much Monster for all of your help. Yet again, you have pointed me in the right direction and increased my knowledge about Blender. Thank you!