void FixedUpdate() { // Get move inputs x = getHorizontal(); y = getVetical(); switch (state) { case MoveState.STOPPED: if (InputManager.GetButton("Submit", player)) { start(); } break; case MoveState.MOVING: // Updating the direction animation variable anim.SetFloat("Direction", x); // Calculate the motion direction vector and scale it by the moveForce speed = (x * transform.parent.right + y * transform.parent.up) * moveForce; // Clamp the speed speed = Vector3.ClampMagnitude(speed, maxMovementSpeed); // Add the player's speed to the rigidbody velocity relative to the parent body.AddRelativeForce(speed, ForceMode.VelocityChange); // Drag TCUtil.Drag(body, body.velocity, drag); // Adjust forward int sec = follower.currenSection; int seg = follower.currentSegment; // Grab tangents from spline int numOfTangets = 10; Vector3 smoothedTangent = new Vector3(0, 0, -5); for (int i = 0; i < numOfTangets; i++) { smoothedTangent = smoothedTangent + Spline.Tangent(spline.vertices, sec, seg, spline.segmentCount, 0); seg++; if (seg >= spline.segmentCount - 1) { seg = 0; sec++; if (sec >= spline.vertices.GetLength(0)) { sec = spline.vertices.GetLength(0) - 1; seg = spline.segmentCount - 2; } } } smoothedTangent.Normalize(); transform.localRotation = Quaternion.Lerp(transform.localRotation, Quaternion.LookRotation(smoothedTangent), .01f); break; case MoveState.END: break; } }
void Update() { switch (state) { case MoveState.END: // At end of level reset camera rotationn //cam.transform.localRotation = Quaternion.Lerp(cam.transform.localRotation, // Quaternion.Euler(0, 0, 0), .1f); break; default: // Get inputs from the camera inputs lookX += InputManager.GetAxis("LookHorizontal", player) * lookSpeed; lookY += InputManager.GetAxis("LookVertical", player) * lookSpeed; // Limit the look axises lookX = Mathf.Clamp(lookX, lookXRestraints.x, lookXRestraints.y); lookY = Mathf.Clamp(lookY, lookYRestraints.x, lookYRestraints.y); // Calculate the rotation using Euler angles, Quaternion rotation = Quaternion.Euler(lookY, lookX, 0); // Set the camera's new rotation cam.transform.localRotation = rotation; break; } Vector2 polar = TCUtil.CartesionToPolar(transform.localPosition); if (polar.x >= .80f && tubCollision) { // TODO: Warn the player if (polar.x >= .90f * tunnelRadius) { transform.localPosition = new Vector3(Mathf.Cos(polar.y) * (.85f * tunnelRadius), Mathf.Sin(polar.y) * (.85f * tunnelRadius), transform.localPosition.z); GetComponent <CargoHealth>().loseCargo(); } } }