Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flipping without changing transform #38

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions CharacterController2D.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class CharacterController2D : MonoBehaviour
private bool m_Grounded; // Whether or not the player is grounded.
const float k_CeilingRadius = .2f; // Radius of the overlap circle to determine if the player can stand up
private Rigidbody2D m_Rigidbody2D;
private SpriteRenderer m_spriteRenderer;
private bool m_FacingRight = true; // For determining which way the player is currently facing.
private Vector3 m_Velocity = Vector3.zero;

Expand All @@ -33,7 +34,7 @@ public class BoolEvent : UnityEvent<bool> { }
private void Awake()
{
m_Rigidbody2D = GetComponent<Rigidbody2D>();

m_spriteRenderer = GetComponent<SpriteRenderer>();
if (OnLandEvent == null)
OnLandEvent = new UnityEvent();

Expand Down Expand Up @@ -135,12 +136,7 @@ public void Move(float move, bool crouch, bool jump)

private 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;
m_spriteRenderer.flipX= !m_FacingRight;
}
}