Hi!
I have a simple movement, and a dash for double tap, but if I have both, I can’t use the dash, because somehow the velocity overwrite the AddForce. Can someone help me with this?
private void Update()
{
Vector2 mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
Vector2 heading = mousePosition - playerRb.position;
Vector2 direction = heading / heading.magnitude;
Vector2 movement = direction * movementSpeed;
Vector2 dash = direction * dashSpeed;
// Double Tap check
if (Input.GetMouseButtonDown(0))
{
float timeSinceLastClick = Time.time - lastClickTime;
if (timeSinceLastClick <= DOUBLE_CLICK_TIME)
{
playerRb.AddForce(dash, ForceMode2D.Impulse);
}
lastClickTime = Time.time;
}
// Simple movement
if (Input.GetMouseButton(0))
{
playerRb.velocity = movement;
// Shooting
if (canShoot)
{
canShoot = false;
bulletPooler.SpawnFromPool("Bullet", transform.position + new Vector3(0, 0.4f), transform.rotation);
StartCoroutine(SetShootBool());
}
}
if(Input.GetMouseButtonUp(0))
{
playerRb.velocity = Vector2.zero;
}
}