I’m using Sebastian Lague platformer 2d code, which uses raycasting.
The code didnt have anything to make the sprite turn left or right depending on what direction you’re going, so I decided to add it, however I ran into a problem; If the player is on a slope and I change the direction (on the X axis) he clips through it.
This is what I added:
void Flip()
{
// Switch the way the player is labelled as facing.
m_FacingRight = !m_FacingRight;
// Multiply the player's x local scale by -1.
Vector3 theScale = transform.localScale;
theScale.x *= -1;
transform.localScale = theScale;
}
The problem seems to be "theScale.x *=-1; Without that line the sprite won’t change when changing directions but it doesnt go through slopes. Help please! I can post the entire code if needed.