#Flip
1 messages · Page 1 of 1 (latest)
hello
the problem is
void Flip(float _velocity)
{
if (_velocity > 0.1f)
{
spriteRenderer.flipX = false;
}
else if (_velocity < -0.1f)
{
spriteRenderer.flipX = true;
}
}
i have this
that flip my caracter and you give me this // void Flip()
// {
// var scale = transform.localScale;
// scale.x *= -1;
// transform.localScale = scale;
// }
how can i use it in my fontion FLIP
yes so my function will reverse the current flip state
so if its flipped it will unflip and vice versa
I would start by making a field that tracks if the object is flipped:
bool isFlipped;
then the doFlipping and flip functions:
void DoFlipping(float _velocity)
{
if (_velocity > 0.1f && isFlipped)
{
Flip();
isFlipped = false;
}
else if (_velocity < -0.1f && !isFlipped)
{
Flip();
isFlipped = true;
}
}
void Flip()
{
var scale = transform.localScale;
scale.x *= -1;
transform.localScale = scale;
}
So you want to call DoFlipping every frame
it will check if you need to flip the object based on the velocity and whether or not its currently flipped
Flip is the code I showed you earlier - it just flips the object
You're welcome 😄