Question by
JaksonHunt17 · Nov 30, 2019 at 05:35 AM ·
unity 2d
Player teleports when using Addforce 2D
Hello,
Im currently trying to repel my character from explosions in a consistent arc, but as you can see from this gif (https://giphy.com/gifs/L2O9xGET7lcWPa0FXH) the character teleports horizontally then slowly rises which is not what i want. Can someone please tell me why this is happening?
My code:
public void addForce ()
{
myRigidBody2d.AddForce(transform.up * magnitude);
myRigidBody2d.AddRelativeForce(transform.right * -700);
}
addForce is triggered by the following method that sits on the explosion gameobject:
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.gameObject.tag == "Player")
{
Player.MyInstance.addForce();
}
}
Comment