How to do dodge Unity2D like Crossing Souls or Hyper Light Drifter.
Hello everyone, I am new in the development of video games and therefore I do not know much about this. I'm creating a top view down game and I'd like to have the character perform an action (dodge) like the Crossing Souls game when you press the defined key. .
. Dodge of crossing souls. . Here I leave the code that I have so far to see if you can help me to carry out this action. .
public class Player : MonoBehaviour
{
public float moveSpeed = 4;
private Vector2 end;
private float movementSpeed;
private Animator anim;
private Rigidbody2D rb2d;
private Vector2 mov;
private void Awake()
{
anim = GetComponent<Animator>();
rb2d = GetComponent<Rigidbody2D>();
}
void Update()
{
TapDodge();
Movement();
Animations();
}
private void FixedUpdate()
{
rb2d.MovePosition(rb2d.position + mov * moveSpeed * Time.deltaTime);
}
void Movement()
{
mov = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));
}
void Animations()
{
if (mov != Vector2.zero)
{
anim.SetFloat("movX", mov.x);
anim.SetFloat("movY", mov.y);
anim.SetBool("Running", true);
}
else
{
anim.SetBool("Running", false);
}
}
void TapDodge()
{
//DODGE
if (Input.GetKeyDown(KeyCode.J))
{
//trigger your animation code here
anim.SetBool("Dodge", true);
}
else
{
anim.SetBool("Dodge", false);
}
}
}
As you can see in the code, I have written that when I pressed the "J" key, the character made the DODGE, but what I could do was that he would only execute the Animator of that action, but he did not perform the action's course.
.
They could help me to establish how much the character has to travel and speed, in the same way that the character can not make any movement while doing the dodge.
,