# Need help with Physics

I'm using Unity to develop a game. Basically i want the player/rocket to follow a point on the screen where user touches. But It's based on physics. Force must be added when user touches somewhere and the rocket has to reach that point. Gravity is there too. If the rocket passes the point then it has to come by using forces. This is the game http://www.flashyland.com/219-jeux-flash-vol-Space-Oil.html (click the red button on the bottom left side and then green button. Arrow keys to play).

The rocket rotates too. I'm not good in physics at all.

• Did you google anything or look at the Unity docs? docs.unity3d.com/ScriptReference/Rigidbody.AddForce.html – Honeybunch Jul 23 '15 at 20:49
• I know how to add force but I'm not asking for it. It's quite complex movement and i can't figure out how to do it. You can check the link posted – Jaspreet Singh Jul 23 '15 at 21:00
• right now you are using arrow keys? What is this about Basically i want the player/rocket to follow a point on the screen where user touches.? – Umair M Jul 24 '15 at 7:27
• that game is not mine. You gonna have to use the keys to play that game. But in my game, the rocket would go where the user touches on the screen. But physics would be the same – Jaspreet Singh Jul 24 '15 at 10:07

I may have interpreted what you want to do incorrectly, but it sounds like what you want to do is have the rocket rotate to look at a point, and then accelerate if the user is touching the screen. I'm not going to help you with the touch input part, but I will assist you in the rotation and actual movement as that seems to be what you asked for

What we need to do first is get the touches position, we need to get it in world space and we want it as a Vector 2. The touch will be in screen space, to convert we can simply run (assuming you have one camera):

Vector3 targetPos = Camera.main.ScreenToWorldPoint(touchPosition);


http://docs.unity3d.com/ScriptReference/Camera.ScreenToWorldPoint.html

Now we have the target position we need to figure out the size of the angle needed to point to targetPos

Vector3 dir = targetPos - transform.position;
float rotZ = Mathf.Atan2(dir.x, dir.y) * Mathf.Rad2Deg;


We call it rotZ because as we are in unity 2d we want to rotate on the z axis.

Next we need to do the actual rotation, for this we need a Rigidbody2D attached. We should access this in the start method of the script

Rigidbody2D RB;
void Start()
{
//Other start work
RB = GetComponent<Rigidbody2D>();
}


Now we have the rigidbody we can do the rotation, we will use the MoveRotation() Method

RB.MoveRotation(-rotZ);


Now the ship is pointing in the right direction we need to add the acceleration, to do this we can use RB.AddForceAtPosition

float Thrust = 5.0f //The amount of force used in the push