Hi, I really need some help with this one! I need to apply force to a character, but because I use my own 2D controller, not physics, I apply my forces in X & Y based on the input. However, I need to apply recoil kickback from the characters gun, in the opposite direction that the gun is facing.
I have the rotation of the transform for the gun, its calculated as per below.
void Update ()
{
Vector2 mousePos = Input.mousePosition;
Vector2 screenPos = Camera.main.ScreenToWorldPoint(new Vector3(mousePos.x, mousePos.y, transform.position.z - Camera.main.transform.position.z));
gun.transform.rotation = Quaternion.Euler(0,0,Mathf.Atan2((screenPos.y - transform.position.y), (screenPos.x - transform.position.x)) * Mathf.Rad2Deg);
}
So my question is, how can I translate that into a force to be applied to the X & Y of the parent object.
For example, if the angle is 45 degrees and I want to apply 20 force. How do I work out how to split that force between the X & Y coords, based on the angle above?