public static void HandleCombat() { //draw firing cones from guns for (int i = 0; i < objs.Count; i++) { Obj o = objs[i]; if (o.range > 0 && o.attachedTo != -1) //Is a gun, and is attached to a unit { Vector3 origin; Vector3 ang; Vector3 leftPos; Vector3 rightPos; Vector3 centerPos; origin = o.go.transform.position; ang = o.go.transform.eulerAngles; centerPos = MathFuncs.ProjectVec(origin, ang, o.range, Vector3.forward); leftPos = MathFuncs.ProjectVec(origin, new Vector3(ang.x, ang.y + o.firingConeAngle, ang.z), o.range, Vector3.forward); rightPos = MathFuncs.ProjectVec(origin, new Vector3(ang.x, ang.y - o.firingConeAngle, ang.z), o.range, Vector3.forward); Effects.DrawLine(origin, leftPos, 0.1f, Effects.Colors.White); Effects.DrawLine(leftPos, centerPos, 0.1f, Effects.Colors.White); Effects.DrawLine(centerPos, rightPos, 0.1f, Effects.Colors.White); Effects.DrawLine(rightPos, origin, 0.1f, Effects.Colors.White); } } }
void Update() { scrollZoomFactor = dist * 0.002f; if (scrollZoomFactor < 0.2f) { scrollZoomFactor = 0.2f; } if (scrollZoomFactor > 1f) { scrollZoomFactor = 1f; } if (CameraNode == null) { //try to find a camera node CameraNode = GameObject.FindGameObjectWithTag("CameraNode"); if (CameraNode != null) { puppet = CameraNode.transform.Find("puppet").gameObject; puppet.SetActive(false); } } if (CameraNode == null) { return; } if (ChatScript.typing) { return; } //Zoom dist += -Input.GetAxis("MouseScrollWheel") * zoomSpd * Time.deltaTime; if (dist < minDist) { dist = minDist; } if (dist > maxDist) { dist = maxDist; } //Rotate node if (Input.GetKey(KeyCode.Space) || (Input.GetMouseButton(1) && (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift)))) { //spin the cameraNode horizontally CameraNode.transform.AddAngY(Input.GetAxis("Horizontal") * turnSpd * Time.deltaTime); //tilt the cameraNode vertically tilt += Input.GetAxis("Vertical") * verTurnSpd * Time.deltaTime; if (tilt < -75) { tilt = maxTilt; } if (tilt > -10) { tilt = minTilt; } } CameraNode.transform.SetAngX(tilt); //Debug.Log("tilt: " + tilt + ", y: " + CameraNode.transform.localEulerAngles.y + ", dist: " + dist); //Move node Vector3 oldAngs = CameraNode.transform.localEulerAngles; CameraNode.transform.SetAngX(0); if (Input.GetKey(KeyCode.W)) { vel.z -= spdAdd * scrollZoomFactor; } if (Input.GetKey(KeyCode.S)) { vel.z += spdAdd * scrollZoomFactor; } if (Input.GetKey(KeyCode.A)) { vel.x += spdAdd * scrollZoomFactor; } if (Input.GetKey(KeyCode.D)) { vel.x -= spdAdd * scrollZoomFactor; } CameraNode.transform.Translate(vel); CameraNode.transform.SetAngX(oldAngs.x); vel *= 0.5f; //Place camera transform.position = MathFuncs.ProjectVec(CameraNode.transform.position, CameraNode.transform.localEulerAngles, dist, Vector3.forward); //Look at CameraNode transform.LookAt(CameraNode.transform.position); }