Controlling the tank

The player can rotate the Turret object using the mouse. This part may be a little bit tricky because it involves raycasting and 3D rotations. The Camera looks down upon the battlefield:

 void UpdateControl() { //AIMING WITH THE MOUSE //Generate a plane that intersects the transform's //position with an upwards normal. Plane playerPlane = new Plane(Vector3.up, transform.position + new Vector3(0, 0, 0)); // Generate a ray from the cursor position Ray RayCast = Camera.main.ScreenPointToRay(Input.mousePosition); //Determine the point where the cursor ray intersects //the plane. float HitDist = 0; // If the ray is parallel to the plane, Raycast will //return false. if (playerPlane.Raycast(RayCast, out HitDist)) { //Get the ...

Get Unity Artificial Intelligence Programming - Fourth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.