- Home /
Question by
Jasfa · Dec 14, 2019 at 02:16 PM ·
2d2d-platformer2d-physicsforcedash
AddForce problem axis X
I'm having trouble adding a dash in my 2d video game, I want the dash to be applied in the mouse direction but it's only being applied to the Y axis and never to the X axis.
void FixedUpdate()
{
x = Input.GetAxisRaw("Horizontal");
y = Input.GetAxisRaw("Vertical");
Walking();
if (Input.GetButtonDown("Jump") && isGrounded == true)
{
Jump();
}
if (Input.GetKeyDown(KeyCode.F))
{
Dash();
}
}
private void Dash()
{
Vector2 pz = Camera.main.ScreenToWorldPoint(Input.mousePosition);
Vector2 dir = new Vector2(pz.x - transform.position.x, pz.y - transform.position.y).normalized;
rb.AddForce(Vector2.right * dashSpeed, ForceMode2D.Impulse);
}
Does anyone know how to fix it? Thank you very much.
Comment
Answer by unity_ek98vnTRplGj8Q · Dec 16, 2019 at 05:29 PM
You seem to create the dir
vector but never use it. Did you mean rb.AddForce(dir * dashSpeed, ForceMode2D.Impulse);
?
Your answer
Follow this Question
Related Questions
Knockback effect in 2D. 1 Answer
Horizontal attraction? 0 Answers
Softbody physics with 2D sprites 1 Answer
How do I move a character WITHOUT acceleration/deceleration? 1 Answer
Jumping from special jump orb 1 Answer