I have it set to add velocity to my player whenever I contact a damaging surface, yet only the y-value is changed (the x-value of the player isn’t locked). How come this is happening?
using UnityEngine;
public class Damage : MonoBehaviour
{
public HealthManager HPscript;
private Rigidbody2D rb;
public float xKnockback;
public float yKnockback;
void Start()
{
GameObject HPmgr = GameObject.Find("HealthManager");
HPscript = HPmgr.GetComponent<HealthManager>();
rb = gameObject.GetComponent<Rigidbody2D>();
}
void OnCollisionEnter2D(Collision2D other)
{
string tag = other.gameObject.tag;
if (tag == "one")
{
HPscript.currentHP -= 1;
rb.velocity = new Vector2(xKnockback, yKnockback);
}
}
}