- Home /
Question by
Woody1066Games · Feb 03 at 11:52 PM ·
2drigidbody2dplayer movement
Unable to use AddForce to Player on X axis due to Player Movement
Hello,
I'm hoping someone can point me in the right direction here. I'm currently moving my player using the following code:
//rb = Rigidbody2D
//mx = Input.GetAxis("Horizontal");
//speed = float for player movement speed
private void FixedUpdate()
{
rb.velocity = new Vector2(mx * speed, rb.velocity.y);
}
The issue I'm having is that this will always override anything I do to try to move the player on the x axis outside of the above code. For example, let's say I try this:
if (Input.GetButtonDown("Fire3"))
{
rb.AddForce(new Vector2(-30, 0f), ForceMode2D.Impulse);
}
The X axis force will not occur because my above fixed update is being called, which cancels it out. I hope that makes sense.
I anyone has any advice I'd really appreciate it!
Comment