When I run this code and press “z”, the player only moves up. On the rare occasion of spamming “z” the player might move decimal places on the x-axis. When I comment out "myRigidBody.velocity = playerVelocity; " then it seems to work but I can’t move then lol. What is the conflict?
{
float control = Input.GetAxis("Horizontal");
Vector2 playerVelocity = new Vector2(control * speed, myRigidBody.velocity.y);
myRigidBody.velocity = playerVelocity;
Vector2 clampedPosition = transform.position;
clampedPosition.x = Mathf.Clamp(clampedPosition.x, minX, maxX);
transform.position = clampedPosition;
if(Input.GetKeyDown(KeyCode.Z))
{
float xBounce = 5f;
myRigidBody.AddForce(new Vector2(xBounce, 5), ForceMode2D.Impulse);
}
if(Input.GetButtonDown("Jump"))
{
Vector2 jumpVelocityToAdd = new Vector2 (0, jumpSpeed);
myRigidBody.velocity += jumpVelocityToAdd;
}
}