Controlling rigidbody.AddForce direction with vector2 angle?


Im hoping someone can help me. I am trying to figure out how to use the angle generated from this code

 if (touch.phase == TouchPhase.Began)
    					fp = touch.position;
    					lp = touch.position;
    				if (touch.phase == TouchPhase.Moved )
    					lp = touch.position;
    					swipeDistanceX = Mathf.Abs((lp.x-fp.x));
    					swipeDistanceY = Mathf.Abs((lp.y-fp.y));
    				if(touch.phase == TouchPhase.Ended)
    					angle = Mathf.Atan2((lp.x-fp.x),(lp.y-fp.y))*57.2957795f;

to set the direction of a rigidbody.Addforce in a vector3.

If I was using translate and rotate functions I would just do this to rotate the object in the direction I’m after.


From what I have read one should avoid the use of transform.rotate when dealing with a rigidbody and physics which is why I’m trying to use the angle to direct the addforce code. Sorry I’m fairly new to coding.

Any help would be appreciated

rigidbody.AddTorque will rotate the object, you can add torque relative to the objects rotation. you can also use rigidbody velocity torque variable on a frame by frame basis for finer control, frame by frame change the velocity torque variable relative to the angle to point change it to a the angle over a number of frames, will avoid using transform rotate, and still keep the physics active.