Day 109 — Setting up Animations for a 2D Platformer

private Animator _anim;void Start()
{
_anim = GetComponentInChildren<Animator>();
}
public void Move(float move)
{
_anim.SetFloat("Move", Mathf.Abs(move));
}
private PlayerAnimation _playerAnim;
private SpriteRenderer _playerSprite;
void Start()
{
_rigidbody = GetComponent<Rigidbody2D>();
_playerAnim = GetComponent<PlayerAnimation>();
_playerSprite = GetComponentInChildren<SpriteRenderer>();

}

void Movement()
{
float move = Input.GetAxisRaw("Horizontal");
if (move > 0)
{
Flip(true);
}
else if (move < 0)
{
Flip(false);
}
if (Input.GetKeyDown(KeyCode.Space) && IsGrounded() == true)
{
_rigidbody.velocity = new Vector2(_rigidbody.velocity.x, _jumpSpeed);
}
_rigidbody.velocity = new Vector2(move * _movementSpeed,
_rigidbody.velocity.y);
_playerAnim.Move(move);
}

void Flip (bool facingRight)
{
if (facingRight == true)
{
_playerSprite.flipX = false;
}
else if (facingRight == false)
{
_playerSprite.flipX = true;
}
}

--

--

--

Hey and welcome! My name is Connor and my goal here is to put out a daily post for a full year about my game development journey.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

THE CROBEES: ROADMAP

How to create Django Admin actions with and without intermediate page

How are product groups used in Shopping campaigns?

Chaos Testing with Istio

How teams spend their time

Airbyte — Open Source Data Integration

GSoC HEAT 4.0 Experience — YT_Downloader (GLUG NIT Durgapur)

T3rm.dev Update: Week 1

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Connor Fullarton

Connor Fullarton

Hey and welcome! My name is Connor and my goal here is to put out a daily post for a full year about my game development journey.

More from Medium

Galaxy Shooter 2D — Boss (Set up)

In-depth Analysis of Unity Loading Module Ⅱ: Shader

Benefits of Prototyping with Cubes

Switch Statements To The Rescue!