protected virtual void Update() { Pitch = Mathf.Clamp(Pitch, -89.9f, 89.9f); var sensitivity = Sensitivity; var camera = Camera; if (camera == null) { camera = Camera.main; } if (camera != null && camera.orthographic == false) { sensitivity *= camera.fieldOfView / 60.0f; } if (Require == KeyCode.None || Input.GetKey(Require) == true) { Pitch -= Input.GetAxisRaw("Mouse Y") * sensitivity; Yaw += Input.GetAxisRaw("Mouse X") * sensitivity; } currentPitch = SgtHelper.Dampen(currentPitch, Pitch, Dampening, Time.deltaTime, 0.1f); currentYaw = SgtHelper.Dampen(currentYaw, Yaw, Dampening, Time.deltaTime, 0.1f); var rotation = Quaternion.Euler(currentPitch, currentYaw, 0.0f); SgtHelper.SetLocalRotation(transform, rotation); }
protected virtual void Update() { if (Thruster != null) { if (Application.isPlaying == true) { FlickerOffset += FlickerSpeed * Time.deltaTime; } if (points == null) { points = new float[128]; for (var i = points.Length - 1; i >= 0; i--) { points[i] = Random.value; } } var noise = Mathf.Repeat(FlickerOffset, points.Length); var index = (int)noise; var frac = noise % 1.0f; var pointA = points[index]; var pointB = points[(index + 1) % points.Length]; var pointC = points[(index + 2) % points.Length]; var pointD = points[(index + 3) % points.Length]; var f = 1.0f - SgtHelper.CubicInterpolate(pointA, pointB, pointC, pointD, frac) * Flicker; throttle = SgtHelper.Dampen(throttle, Thruster.Throttle, Dampening, Time.deltaTime); transform.localScale = BaseScale + ThrottleScale * throttle * f; } }
protected virtual void Update() { var camera = Camera; if (camera == null) { camera = Camera.main; } if (camera != null) { if (currentZoom == 0.0f) { if (camera.orthographic == true) { currentZoom = camera.orthographicSize; } else { currentZoom = camera.fieldOfView; } Zoom = currentZoom; } if (Require == KeyCode.None || Input.GetKey(Require) == true) { var scroll = Input.mouseScrollDelta.y; if (scroll > 0.0f) { Zoom *= 1.0f - Sensitivity; } if (scroll < 0.0f) { Zoom *= 1.0f + Sensitivity; } } Zoom = Mathf.Clamp(Zoom, ZoomMin, ZoomMax); currentZoom = SgtHelper.Dampen(currentZoom, Zoom, Dampening, Time.deltaTime, 0.1f); if (camera.orthographic == true) { camera.orthographicSize = currentZoom; } else { camera.fieldOfView = currentZoom; } } }
public void RotateFun(Transform rotatething, Vector3 pos) { Yaw = Mathf.Clamp(Yaw, MinmaxX.x, MinmaxX.y); Pitch = Mathf.Clamp(Pitch, MinmaxY.x, MinmaxY.y); Yaw += pos.x * Sensitivity; Pitch -= pos.y * Sensitivity; currentYaw = SgtHelper.Dampen(currentYaw, Yaw, Dampening, Time.deltaTime * 0.2f, 0.1f); currentPitch = SgtHelper.Dampen(currentPitch, Pitch, Dampening, Time.deltaTime * 0.2f, 0.1f); var rotation = Quaternion.Euler(currentPitch, currentYaw, 0); SgtHelper.SetRotation(rotatething, rotation); }
protected virtual void Update() { TargetPitch = Mathf.Clamp(TargetPitch, -89.9f, 89.9f); if (Require == KeyCode.None || Input.GetKey(Require) == true) { TargetPitch -= Input.GetAxisRaw("Mouse Y") * Sensitivity; TargetYaw += Input.GetAxisRaw("Mouse X") * Sensitivity; } currentPitch = SgtHelper.Dampen(currentPitch, TargetPitch, Dampening, Time.deltaTime, 0.1f); currentYaw = SgtHelper.Dampen(currentYaw, TargetYaw, Dampening, Time.deltaTime, 0.1f); var rotation = Quaternion.Euler(currentPitch, currentYaw, 0.0f); SgtHelper.SetLocalRotation(transform, rotation); }
private void CameraPreCull(Camera camera) { if (Thruster != null) { var visibility = GetThrusterVisibility(camera); var rotation = camera.transform.rotation; // * observer.RollQuataternion; // Resize visibility.Scale = SgtHelper.Dampen(visibility.Scale, visibility.Visible == true ? 1.0f : 0.0f, Dampening, Time.unscaledDeltaTime, 0.1f); // Point flare at camera if (tempSet == false) { tempSet = true; tempRotation = transform.rotation; tempScale = transform.localScale; } transform.rotation = rotation; transform.localScale = finalScale * visibility.Scale; } }
// This static method will rotate the transform to the surface of the terrain below public static void SnapTransformRotation(SgtTerrain terrain, Transform transform, float rightDistance = 1.0f, float forwardDistance = 1.0f, float dampening = 0.0f) { if (terrain != null && transform != null) { var newNormal = default(Vector3); // Rotate to surface normal? if (rightDistance != 0.0f && forwardDistance != 0.0f) { var worldRight = transform.right * rightDistance; var worldForward = transform.forward * forwardDistance; newNormal = terrain.GetWorldNormal(transform.position, worldRight, worldForward); } // Rotate to planet center? else { newNormal = terrain.GetWorldNormal(transform.position); } var oldRotation = transform.rotation; var newRotation = Quaternion.FromToRotation(transform.up, newNormal) * oldRotation; //if (oldRotation != newRotation) { if (dampening > 0.0f) { transform.rotation = SgtHelper.Dampen(transform.rotation, newRotation, dampening, Time.deltaTime); } else { transform.rotation = newRotation; } } } }
protected virtual void Update() { if (Follower == null) { ClearDebris(); return; } var followerPosition = Follower.position; var followerDensity = GetDensity(followerPosition); if (followerDensity > 0.0f) { var debrisCount = Debris != null ? Debris.Count : 0; if (debrisCount < SpawnLimit) { spawnCooldown -= Time.deltaTime; while (spawnCooldown <= 0.0f) { spawnCooldown += Random.Range(SpawnRateMin, SpawnRateMax); SpawnDebris(false); debrisCount += 1; if (debrisCount >= SpawnLimit) { break; } } } } if (Debris != null) { var distanceRange = HideDistance - ShowDistance; for (var i = Debris.Count - 1; i >= 0; i--) { var debris = Debris[i]; if (debris != null) { var targetScale = default(float); var distance = Vector3.Distance(followerPosition, debris.transform.position); // Fade its size in debris.Show = SgtHelper.Dampen(debris.Show, 1.0f, ShowSpeed, Time.deltaTime, 0.1f); if (distance < ShowDistance) { targetScale = 1.0f; } else if (distance > HideDistance) { targetScale = 0.0f; } else { targetScale = 1.0f - SgtHelper.Divide(distance - ShowDistance, distanceRange); } debris.transform.localScale = debris.Scale * debris.Show * Mathf.Max(minScale, targetScale); if (targetScale <= 0.0f) { Despawn(debris, i); } } else { Debris.RemoveAt(i); } } } }