How does this work?

Hey guys, a really stupid question, but I don’t understand something pretty basic here.

grounded = (controller.Move(moveDirection * Time.deltaTime)  CollisionFlags.Below) != 0;

How does this line work? I don’t get it… how “grounded” gets set to true or false here and why is there that “” between Move and collision flags and finally - why is there a “!=0” what does it do? Preventing a null result or something?

The int returned by the Move function is actually interpreted as a set of bit flags.

This page has some explaining about that concept:

Note that it is C#, but for the concept of bit flags, the language is pretty much irrelevant. It works the same in C/C++ or Java, for instance. So if you want more information, just googling for ‘bit flags’ should give you plenty of hits.

Thanks, that is some nice information! I couldn’t understand everything, but some things became clear. So if I’m touching the ground, the collision flag “Below” would return some value, different than 0. and it checks if it’s value is different.

But I still don’t get one thing after reading what you gave me. I mean, it was there for example, but I still couldn’t understand it. What is the controller.Move function doing in this case ? I know it outputs a value that is CollisionFlags. So it checks if there’s a collision flag and it’s differend than zero or I am wrong in my understanding ?

Edit:
I think I understood it :smile: !
Move returns a number, that get’s compared to CollisionFlags.Below and if that number isn’t 0, than grounded will be true. So (little syntax question)this “” is used to compare flags. I tried googling it, but I didn’t find information about this.