Answer the question
In order to leave comments, you need to log in
Unity3D 5 - Speed, direction, physics?
The character has 2d physics. The character has a script component. Everything works, except for one section.
void FixedUpdate()
{
if (velocity.y > 0.1)
{
Debug.Log("Up Jump");
this.GetComponent<SpriteRenderer>().sprite = this.upJump;
}
else if (velocity.y < 0.1)
{
Debug.Log("Down Jump");
this.GetComponent<SpriteRenderer>().sprite = this.downJump;
}
else if (velocity.y == 0.0)
{
Debug.Log("NOT Jump");
}
}
Answer the question
In order to leave comments, you need to log in
Rule: never compare real numbers for equality (e.g. representation errors, rounding errors, etc.)
...
else if ( Math.Abs(velocity.y) <= 0.1 )
{
Debug.Log("NOT Jump");
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question