Question by
erikiene · Nov 03, 2016 at 12:03 PM ·
unity 5rotationscripting beginnerplatformer2.5d
2.5D platformer character turn around (180)
Trying to have my player character turn around when he starts moving in the opposite direction. I have previously used localScale as I dabbled with 2D before but while it works, you can imagine it doesn't look too great (logic implementation below). I tried a number of things, mostly related to rotating the character, but to no avail. Advice or hints on how to properly rotate the character so it looks alright AND the logic checks that would go behind that would be much appreciated!
Vector3 localScale = _transform.localScale;
if (_vx > 0)
{
facingRight = true;
}
else if (_vx < 0)
{
facingRight = false;
}
if ((facingRight && localScale.z < 0) || (!facingRight && localScale.z > 0))
{
localScale.z *= -1;
}
_transform.localScale = localScale;
p.s. _vx reads the horizontal input
Desired effect - https://youtu.be/9qhH9GWLtRo?t=50
Comment