protected override void Update() { base.Update(); if (Controllable) { Supercruise = !Aligned && Input.GetKey(KeyCode.T); if (Input.GetMouseButton(0) && !MouseOverUI) { RayScreen = CameraComponent.ScreenPointToRay(Input.mousePosition); var gravityVector = (RayScreen.origin + RayScreen.direction * 10.0f) - transform.position; TargetRotation = Quaternion.LookRotation(gravityVector, transform.up); Rotation.z = 0; RotateSlerp(Time.deltaTime * RotationSpeed); } else if (Input.GetMouseButton(1) && !MouseOverUI) { RotateAround(true); // NOTE : Force this rotation mode... } else { if (!Aligned) { if (Input.GetKey(KeyCode.E)) { Rotation.z -= 0.20f * Time.deltaTime; } else if (Input.GetKey(KeyCode.Q)) { Rotation.z += 0.20f * Time.deltaTime; } else { Rotation.z = Mathf.Lerp(Rotation.z, 0, Time.deltaTime * 1.25f); } Rotation.z = Mathf.Clamp(Rotation.z, -100.0f, 100.0f); transform.Rotate(new Vector3(0, 0, Rotation.z)); if (Input.GetKey(KeyCode.G)) { var gravityVector = (Body != null ? Body.Origin : Vector3.zero) - transform.position; TargetRotation = Quaternion.LookRotation(gravityVector, transform.up); RotateSlerp(Time.deltaTime * RotationSpeed * 1.57f); } } } // NOTE : Body shape dependent... if (Aligned) { var gravityVector = (Body != null ? Body.Origin : Vector3.zero) - transform.position; TargetRotation = Quaternion.LookRotation(transform.forward, -gravityVector); RotateSlerp(Time.deltaTime * RotationSpeed * 3.0f); } Velocity.z = Input.GetAxis("Vertical"); Velocity.y = Input.GetAxis("Diagonal"); Velocity.x = Input.GetAxis("Horizontal"); CurrentSpeed = Speed; if (Input.GetKey(KeyCode.LeftShift)) { CurrentSpeed = Speed * 10f; } if (Input.GetKey(KeyCode.LeftControl)) { CurrentSpeed = Speed * 100f; } if (Input.GetKey(KeyCode.LeftShift) && Input.GetKey(KeyCode.LeftControl)) { CurrentSpeed = Speed * 1000f; } if (Input.GetKey(KeyCode.LeftAlt)) { CurrentSpeed = Speed / 10f; } if (!MouseOverUI) { Speed += Mathf.RoundToInt(Input.GetAxis("Mouse ScrollWheel") * 100.0f); Speed = Mathf.Clamp(Speed, 1.0f, 100000000.0f); } if (Supercruise) { CurrentSpeed *= 1000.0f; } transform.Translate(Velocity * CurrentSpeed); } }
protected override void FixedUpdate() { base.FixedUpdate(); UpdateClipPlanes(); if (controllable) { if (Input.GetMouseButton(0) && !MouseOverUI) { rotation.z = 0; ray = CameraComponent.ScreenPointToRay(Input.mousePosition); targetRotation = Quaternion.LookRotation((ray.origin + ray.direction * 10.0f) - transform.position, transform.up); transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, Time.fixedDeltaTime * rotationSpeed); if (!aligned) { transform.Rotate(new Vector3(0.0f, 0.0f, rotation.z)); } } else if (Input.GetMouseButton(1) && !MouseOverUI) { RotateAround(true); // NOTE : Force this rotation mode... } else { if (Input.GetKey(KeyCode.E)) { rotation.z -= 1.0f * Time.deltaTime; } else if (Input.GetKey(KeyCode.Q)) { rotation.z += 1.0f * Time.deltaTime; } else { rotation.z = Mathf.Lerp(rotation.z, 0, Time.deltaTime * 2.0f); } rotation.z = Mathf.Clamp(rotation.z, -100.0f, 100.0f); if (!aligned) { transform.Rotate(new Vector3(0, 0, rotation.z)); } } if (planetoidGameObject != null) { distanceToPlanetCore = Vector3.Distance(transform.position, planetoidGameObject.transform.position); if (distanceToPlanetCore < alignDistance) { aligned = true; var gravityVector = planetoidGameObject.transform.position - transform.position; targetRotation = Quaternion.LookRotation(transform.forward, -gravityVector); transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, Time.fixedDeltaTime * rotationSpeed * 3f); } else { aligned = false; } } velocity.z = Input.GetAxis("Vertical"); velocity.x = Input.GetAxis("Horizontal"); currentSpeed = speed; if (Input.GetKey(KeyCode.LeftShift)) { currentSpeed = speed * 10f; } if (Input.GetKey(KeyCode.Space)) { currentSpeed = speed * 100f; } if (Input.GetKey(KeyCode.LeftShift) && Input.GetKey(KeyCode.Space)) { currentSpeed = speed * 1000f; } if (Input.GetKey(KeyCode.LeftControl)) { currentSpeed = speed / 10f; } speed += Mathf.RoundToInt(Input.GetAxis("Mouse ScrollWheel") * 100.0f); speed = Mathf.Clamp(speed, 1.0f, 10000.0f); transform.Translate(velocity * currentSpeed); } /* * var cameraPosition = transform.position; * var universe = FindObjectOfType<Universe>(); * * if (Math.Abs(cameraPosition.magnitude) > 5000.000f) * { * universe.transform.position -= cameraPosition; * transform.position = Vector3.zero; * } */ }
protected override void FixedUpdate() { base.FixedUpdate(); UpdateDistances(); UpdateClipPlanes(); if (Controllable) { Supercruise = !Aligned && Input.GetKey(KeyCode.F); if (Input.GetMouseButton(0) && !MouseOverUI) { Rotation.z = 0; RayScreen = CameraComponent.ScreenPointToRay(Input.mousePosition); TargetRotation = Quaternion.LookRotation((RayScreen.origin + RayScreen.direction * 10.0f) - transform.position, transform.up); transform.rotation = Quaternion.Slerp(transform.rotation, TargetRotation, Time.fixedDeltaTime * RotationSpeed); if (!Aligned) { transform.Rotate(new Vector3(0.0f, 0.0f, Rotation.z)); } } else if (Input.GetMouseButton(1) && !MouseOverUI) { RotateAround(true); // NOTE : Force this rotation mode... } else { if (Input.GetKey(KeyCode.E)) { Rotation.z -= 1.0f * Time.deltaTime; } else if (Input.GetKey(KeyCode.Q)) { Rotation.z += 1.0f * Time.deltaTime; } else { Rotation.z = Mathf.Lerp(Rotation.z, 0, Time.deltaTime * 2.0f); } Rotation.z = Mathf.Clamp(Rotation.z, -100.0f, 100.0f); if (!Aligned) { transform.Rotate(new Vector3(0, 0, Rotation.z)); } } if (Body.GetBodyDeformationType() == BodyDeformationType.Spherical) { if (DistanceToCore < DistanceToAlign) { Aligned = true; var gravityVector = Body.transform.position - transform.position; TargetRotation = Quaternion.LookRotation(transform.forward, -gravityVector); transform.rotation = Quaternion.Slerp(transform.rotation, TargetRotation, Time.fixedDeltaTime * RotationSpeed * 3f); } else { Aligned = false; } } else { Aligned = false; } Velocity.z = Input.GetAxis("Vertical"); Velocity.x = Input.GetAxis("Horizontal"); CurrentSpeed = Speed; if (Input.GetKey(KeyCode.LeftShift)) { CurrentSpeed = Speed * 10f; } if (Input.GetKey(KeyCode.LeftControl)) { CurrentSpeed = Speed * 100f; } if (Input.GetKey(KeyCode.LeftShift) && Input.GetKey(KeyCode.LeftControl)) { CurrentSpeed = Speed * 1000f; } if (Input.GetKey(KeyCode.LeftAlt)) { CurrentSpeed = Speed / 10f; } Speed += Mathf.RoundToInt(Input.GetAxis("Mouse ScrollWheel") * 100.0f); Speed = Mathf.Clamp(Speed, 1.0f, 100000000.0f); if (Supercruise) { CurrentSpeed *= 1000.0f; } transform.Translate(Velocity * CurrentSpeed); } if (Body != null) { var worldPosition = (Vector3d)(transform.position - Body.Origin); if (Body.GetBodyDeformationType() == BodyDeformationType.Spherical) { if (worldPosition.Magnitude() < Body.Size + 10.0 + Body.HeightZ) { worldPosition = worldPosition.Normalized(Body.Size + 10.0 + Body.HeightZ); } } else { if (worldPosition.z < 10.0 + Body.HeightZ) { worldPosition.z = 10.0 + Body.HeightZ; } } transform.position = worldPosition + (Vector3d)Body.Origin; } }