Can I use both (addforce) and (velocity) in one script with no issues?
I'm using the velocity to move the gameobject left and right. Now, I wanted to make it slide using (addforce), however; it is not working properly. The (addforce) does not work as intended if I silde it looks like as if I'm teleporting.
Slide method:
private void Slide()
{
if (Input.GetKeyDown(KeyCode.LeftShift))
{
if(facingRight)
{
PlayerRigidBody.AddForce(Vector2.right * slideSpeed);
animator.SetTrigger("slide");
}
else
{
PlayerRigidBody.AddForce(Vector2.left * slideSpeed);
animator.SetTrigger("slide");
}
}
Run Method:
private void Run()
{
xMovement = Input.GetAxisRaw("Horizontal");
Vector2 playerVelocity = new Vector2(xMovement * speed, PlayerRigidBody.velocity.y);
PlayerRigidBody.velocity = playerVelocity;
PlayerRunAnimation();
}
Comment
Your answer
