How to create an idle state by specifying the character is not moving
Asked Answered
A

4

0

I tried to create an idle state by saying "if velocity == 0:", but I get an error saying "Invalid operands 'Vector2' and 'int' for '==' operator".

It seems like it only works if you say "velocity.x" or "velocity.y", but my character moves all around the screen. I'm just trying to figure out how to specify that the general velocity is 0.

Arlin answered 19/2 at 18:59 Comment(0)
E
0

Velocity is a Vector3 and you tried to compare it to an integer.
You have to compare it against the same type.

Try if velocity == Vector3.ZERO:

if !velocity: should do the same thing like theabove I believe.
Only issue is when using gravity. Then your velocity.y might not be 0 and therefore this check won't work.

Ebonyeboracum answered 19/2 at 19:15 Comment(0)
A
0

Ebonyeboracum Thanks. Does this work for 2D as well with Vector2?

Arlin answered 19/2 at 19:21 Comment(0)
E
1

Arlin Yes it should.

Ebonyeboracum answered 19/2 at 19:29 Comment(0)
A
0

Ebonyeboracum Thanks

Arlin answered 19/2 at 22:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.