Jondolf / avian

ECS-driven 2D and 3D physics engine for the Bevy game engine.
https://crates.io/crates/avian3d
Apache License 2.0
1.54k stars 120 forks source link

Gravity is suddenly default "on" only if ExternalForce is used, but default off otherwise #526

Open aDecoy opened 1 month ago

aDecoy commented 1 month ago

Hi, this is a confusing non intuitive change in default behaviour that showes up if one updates ExternalForces, and I feel like it is a bug.

How i found the strange behaviour/maybe-bug

I had commented out // .insert_resource(Gravity(Vector::NEG_Y * 9.81 * 100.0)), but my blocks were still falling down. Very confusing. It stoped falling down if i never updated ExternalForce. If i used myForceFromQuery.apply_force(Vector::ZERO);, it would start to fall again. I thought it might be something wrong with the forces.

After printing stuff in avian2d-0.1.2/src/dynamics/integrator/mod.rs:214, i learned that it uses the default 9.81 gravity. Indeed, if i spesificly set gravity to zero, then this behaviour is gone. .insert_resource(Gravity::ZERO).

It is very confusing that gravity is default off, but suddenly becomes default earth-gravity if I update the ExternalForces. It might be that it internally always is default -9.81, but never used unless one starts to use ExternalForces. I dont know, but it was confusing

What i suggest should change:

Gravity should have the same default for Entities, with and without updates to ExternalForces. (I would preffer off, but as long as it is the same i am ok with it)

Alternativly:

If this is intended behaviour, I feel that we need a note on this in the documentation https://docs.rs/avian2d/latest/avian2d/dynamics/rigid_body/struct.ExternalForce.html

🫡 Thanks for listening

Other than this I am having a great first experience with Avian so far 👍 😃