- Home /
2D sprite character movement
Hey i'm currently making a 2D game based with sprites, I've got spritemanager 2 and the sprite sheets ready, could anyone try to explain how i make the character move and animate when i press the ¨right button¨. Like how to make the character movie and animate the right animation for which way i'm walking.
This tutorial should get you going. There isn't really any "short answer" that wouldn't lead to more questions.
Answer by Nasnas · Feb 16, 2016 at 12:57 PM
I think you are meaning this
public Animator Anim;
void Update()
{
transform.Translate(Input.GetAxisRaw("Vertical"), 0f, 0f, Space.World);
if (Input.GetAxisRaw("Vertical") == 1)
{
Anim.SetBool("YourLeftMovementAnimation", false);
Anim.SetBool("YourRightMovementAnimation", true);
Anim.SetBool("YourStandingAnimation", false);
//You have to set bools to control the animations in the animation window so then you can play them when you want
}
else if (Input.GetAxisRaw("Vertical") == -1)
{
Anim.SetBool("YourLeftMovementAnimation", true);
Anim.SetBool("YourRightMovementAnimation", false);
Anim.SetBool("YourStandingAnimation", false);
}
else
{
Anim.SetBool("YourLeftMovementAnimation", false);
Anim.SetBool("YourRightMovementAnimation", false);
Anim.SetBool("YourStandingAnimation", true);
}
}
This only for left and right movement and the animation thing, but when it comes to jumping you have to do raycasting or use CharacterController
Answer by PheonyXtreme · Feb 16, 2016 at 12:59 PM
Hey there:) It seems you are new to this (no worries, I'm not expert either) so I advice you to check some good tutorials on youtube. There is a 2d platformer course made by Brackeys. He teaches you from character controling to camera adjustments, backgrounds, animations, sounds... That course is for Begginners/Intermediates. He teached me mostly all I know at the moment, so i'll be glad if he can help with your problems:)
Answer by Zoogyburger · Feb 15, 2016 at 08:14 PM
Take a look at this:
https://www.youtube.com/watch?v=TU6wflRqT5Q
https://www.youtube.com/watch?v=Oao-A7bkve0∈dex=3&list=PLiyfvmtjWC_X6e0EYLPczO9tNCkm2dzkm
Your answer
Follow this Question
Related Questions
How can i start a 2D animation via script 1 Answer
How do I stop sprite animation on last frame? 2 Answers
Anima2d: How to use a single sprite for two paws? 0 Answers
How to make not smooth animation? 0 Answers