#Flip

1 messages · Page 1 of 1 (latest)

ebon wadi
#

So what's the problem?

steep merlin
#

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

ebon wadi
#

yes so my function will reverse the current flip state

#

so if its flipped it will unflip and vice versa

steep merlin
#

yes but i am a noob

#

where do i have to place it x)

ebon wadi
#

I would start by making a field that tracks if the object is flipped:

bool isFlipped;
steep merlin
ebon wadi
#

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

steep merlin
#

okay gonna try

#

don' work

#

flip bad

ebon wadi
#

dont flip the spriterenderer as well

#

its gonna do that for you

steep merlin
#

OHHH

#

okayyy

#

IT WOOOORK

ebon wadi
#

You're welcome 😄