# What is velocity.y

I am using velocity.y for ground checking but I do not literally understand what velocity actually is !

``````if (isGrounded && velocity.y <0)
{
velocity.y = -2f;
}
``````

in this how can a bool (isGrounded) be less than 0 like it has to be 0 or 1

And what is this?

``````velocity.y += gravity * Time.deltaTime;
controller.Move(velocity * Time.deltaTime);
``````

You mean in this context, or velocity in general? velocity.y is the y (vertical) axis of a velocity vector.

In C# bools can only be true or false.

if (isGrounded && velocity.y <0)
Shortcut for
if (isGrounded == true && velocity.y <0)

A beginner course in c# programming might help you more than trying to get people to spell every line of code out for you.

1 Like

Though I can understand the need to explain this, I have a beef with your choice of words, because itâ€™s not a shortcut.

`if` clause absolutely requires a Boolean expression, you see. With Boolean expressions, numerical arithmetic is invalid and the only valid values are true and false. Similarly the only valid operations are logical and relational (because theyâ€™re the only ones to give results in Boolean values).

Any expression that refers to a `bool` variable will thus evaluate the underlying Boolean value.
For this reason `IsGrounded` should not be considered a shortcut, but `isGrounded == true` should be considered a redundant and misleading operation.

Itâ€™s like saying `if(true == true)`. Howâ€™s that beneficial?

Sure it maybe helps beginners understand whatâ€™s going on, but in my opinion it also hides the true nature of Boolean expressions.

Now this is a shortcut that people sometimes use with UnityEngine.Object objects

``````if(!GetComponent<Whatever>()) {
//...
}
``````

This only works because Unity has implemented an implicit cast for Boolean expressions. click
It doesnâ€™t work for other objects in C#, and I personally donâ€™t like this idea because it confuses people a lot.
It emulates a behavior seen in softer languages (where a missing reference would evaluate to `null` and thus interpret as `false`), yet fools you into thinking itâ€™s a C# thing. Itâ€™s not, and it violates the strictness of C#. Because of this, this deserves to be called a dirty shortcut.

Mmmmmm â€¦ OKAYYYYY
I let you fight with semanticsâ€¦

1 Like

You donâ€™t know if the first part is true, so it is beneficialâ€¦

Yes, doing a boolean comparison to get another boolean instead of straight up using the boolean is a bit silly, but also it is a bit easier to read and Iâ€™m fairly sure both things compile down to the exact same thing, so whatever.

If only you could explain velocity to the OP with the same verbosity and gusto.

1 Like

@alexeu
@AcidArrow
Guys, I donâ€™t know if you can tell, Iâ€™m not nitpicking, thatâ€™s a poor form. Itâ€™s not nearly something like style or â€śfighting semanticsâ€ť. You reveal that you donâ€™t understand code AT ALL. Iâ€™m trying to teach you something.

What are you? Web developers? Good luck with the attitude.

Man, this sentence makes so little senseâ€¦
If you canâ€™t understand a word of what I said, you honestly should not have replied.

I donâ€™t know if you can tell from the first comment, but this thread is a clone. There is a whole another thread from the same guy where it was already explained. And it wasnâ€™t enough for him.

Enjoy.

IMO, doing bool == true comparisons is beneficial, because if you decide to switch your bool to a nullable bool? at some point, your code still works.

And if the type is not nullable, they compile to the same thing, meaning thereâ€™s no performance benefit, making this more or less, a semantics argument.

1 Like

Donâ€™t you hate it when in the midst of the project you change the variable type, and it doesnâ€™t work anymore?
Wow. So useful.

Because youâ€™re searching on Google for a good reply, hereâ€™s another excellent snippet

``````bool isNothingButTrue(bool c) {
if(c == true && c != false) return true; else return false;
}
``````

Maybe you find that practice suitable, or a â€śsemantics argumentâ€ť, just please stop sharing advice.

Could we please keep on topic in this thread and refrain from getting personal with one another?

1 Like