How to Send Rigidbody2d at a certain angle or direction?

I’m currently using the EasyTouch set of assets and I have a swipe currently working great. However, at the end of the swipe, I need the code to send the spite/rigidbody2d at what ever angle the swipe ends at on screen. Currently I have this:

	private void On_SwipeEnd(Gesture gesture){

			

			float angles = gesture.GetSwipeOrDragAngle();
			print (angles);
			
			var leafPlayer = GameObject.FindGameObjectWithTag("Player");
			var leafPlayerPos = leafPlayer.transform.position.x;
			leafPlayer.rigidbody2D.AddForce(new Vector2(leafPlayerPos, angles) * 5);

		}

But obviously this isn’t quite doing it. The leafPlayer gets sent into weird spins and what not. I just need it to go the direction where the angle is pointing after the swipe ends. Any ideas? Is rigidbody2d even the way to go?

This is difficult to answer since I don’t know your Gesture class. But what you are doing here is not correct. You cannot build a vector using one component position and one componet an angle. There are two ways you can approach this problem. The most direct would be to get the start and end positions of the Gesture if it is avaliable, Subtract start from end will give you a vector for your AddForce. Be sure to normalize the result.

The second way would be to use your angle and a reference vector. I don’t know where the 0 reference is for ‘angles’. Let’s assume it is Vector3.right. If so, then you can do:

var dir = Quaternion.AngleAxis(angles, Vector3.forward) * Vector3.right;
leafPlayer.rigidbody2d.AddForce(dir * 5.0);