- Home /
Need suggestion or advice on my 2d platformer
Need suggestion or advice on my 2d platformer
Hi, this is my first time posting in here. I have been studying how to create a 2D platformer for nearly a week. I used the GBA Castlevania Aria of Sorrow as the reference to recreate the control on Soma Cruz. I have recreated a few of his major movement with animation controller. Currently I am having a problem deciding how to arrange or change the node in the Animator, because it have become messy.
There are two think I need help with.
1- What further improvement can I do to the Animator controller (Image below)?
2- I need some criticism on the PlayerController C# Script I have.
Thanks
void Start ()
{
r2d = GetComponent<Rigidbody2D> ();
cColl = GetComponent<CircleCollider2D> ();
rend = GetComponent<SpriteRenderer> ();
anim = GetComponent<Animator> ();
afterimage = transform.FindChild("AfterImage").gameObject;
}
void Update ()
{
anim.SetFloat("verticalSpeed", r2d.velocity.y);
direction = 0.0f;
if (isGrounded)
{
anim.SetInteger ("state", 0); // Idle
}
else
{
anim.SetInteger ("state", 3); // Fall
}
anim.SetBool("isGrounded",isGrounded);
if (!isBackDashing)
{
if (Input.GetKey(KeyCode.RightArrow)) //Move Right
{
rend.flipX = false; // Face Right
anim.SetInteger("state", 1); // Walk
direction = 1.0f; // To The Right
}
if (Input.GetKey(KeyCode.LeftArrow)) //Move Left
{
rend.flipX = true; // Face Left
anim.SetInteger("state", 1); // Walk
direction = -1.0f; // To The Left
}
if (Input.GetKey(KeyCode.DownArrow) && isGrounded) //Crouch/Duck
{
direction = 0.0f; // Stop And
anim.SetInteger("state", 2); // Duck
}
if (Input.GetKey(KeyCode.UpArrow)) //Cast
{
//Blank
}
}
if (Input.GetKeyDown(KeyCode.Z) //Jump
&& isGrounded && anim.GetInteger("state") != 2)
{
if (isBackDashing)
{
isBackDashing = false;
afterimage.SetActive(false);
}
r2d.velocity = new Vector2(r2d.velocity.x,jumpHeight);
anim.SetInteger("state", 3); // Jump
anim.SetBool("isGrounded",isGrounded);
}
if (Input.GetKeyDown(KeyCode.A) //BackDash
&& isGrounded && !isBackDashing)
{
isBackDashing = true;
afterimage.SetActive(true);
}
if (isBackDashing)
{
if (rend.flipX)
{
r2d.velocity = new Vector2(backDashSpeed,r2d.velocity.y);
anim.SetInteger("state", 4);
}
else
{
r2d.velocity = new Vector2(-backDashSpeed,r2d.velocity.y);
anim.SetInteger("state", 4);
}
}
else
{
r2d.velocity = new Vector2(direction * walkSpeed,r2d.velocity.y);
}
}
It seems like all your animations connect to all the animations and don't necessarily rely on a flow of sorts. So why not use the Any State feature?
I'm not sure weather to use it or not that is where my problem is. The Any State node is one of the option that is currently on the table, I will have to look into this further.