[Unity 2D] Knockback in a 2D platformer

I’m trying to get my character to be knocked back by attacks from enemies.
At the moment I have this:

rigidbody2D.velocity = new Vector2 (0, 0);
		GetComponent<MovementScript> ().enabled = false;

		Vector3 EnemyDirection = ((transform.position.x - enemy.position.x)>0?rightvec:leftvec) + (Vector3.up);
		this.rigidbody2D.velocity = (EnemyDirection * force);

		Debug.Log (EnemyDirection);

		GetComponent<MovementScript> ().enabled = true;

However my character goes straight up rather being knocked into a direction. Any suggestion why this might be?

Any help is much appreciated, thanks. :slight_smile:

Dunno if there is some helper class in unity but from maths.

Its actually Javacode but i think you get the idea what to calculate

double radian = Math.toRadians(MathUtil.convertHeadingToDegree(effector.getHeading()));

float x1 = (float) (Math.cos(radian) * meters);
float y1 = (float) (Math.sin(radian) * meters);

// new position
float newX = effected.getX() + x1;
float newY = effected.getX() + y1;

// Update pos with new x,y