void ICmpUpdatable.OnUpdate() { Transform transform = this.GameObj.Transform; Camera camera = this.GameObj.GetComponent <Camera>(); transform.Pos -= this.screenShakeOffset; transform.Angle -= this.screenShakeAngle; Vector3 focusPos = this.targetObj.Transform.Pos; Vector3 targetPos = focusPos - new Vector3(0.0f, 0.0f, camera.FocusDist / MathF.Max(this.zoomLevel, 0.01f)) * (1.0f + this.extraDist); this.extraDist = MathF.Max(0.0f, this.extraDist - Time.TimeMult * Time.SPFMult * 0.15f); this.extraDist = MathF.Max(this.extraDist, MathF.Clamp((focusPos.Xy - transform.Pos.Xy).Length / 500.0f, 0.0f, 1.0f)); Vector3 posDiff = (targetPos - transform.Pos); Vector3 targetVelocity = posDiff * 0.1f * MathF.Pow(2.0f, -this.smoothness); transform.MoveByAbs(targetVelocity * Time.TimeMult); this.screenShakeOffset = this.screenShake * MathF.Rnd.NextVector3(75.0f); this.screenShakeAngle = this.screenShake * 0.2f * MathF.Rnd.NextFloat(-1.0f, 1.0f); this.screenShake += (0.0f - this.screenShake) * 0.075f * Time.TimeMult; if (this.screenShake < 0.01f) { this.screenShake = 0.0f; } transform.Pos += this.screenShakeOffset; transform.Angle += this.screenShakeAngle; }
void ICmpUpdatable.OnUpdate() { if (this.camera == null) { return; } if (this.microphone == null) { return; } Transform camTransform = this.camera.GameObj.Transform; Transform microTransform = this.microphone.GameObj.Transform; // Update screen shake behavior Vector3 lastScreenShakeOffset = this.screenShakeOffset; float lastScreenShakeAngle = this.screenShakeAngle; this.screenShakeOffset = MathF.Rnd.NextVector3() * 100.0f * this.screenShake; this.screenShakeAngle = MathF.Rnd.NextFloat(-1.0f, 1.0f) * MathF.DegToRad(5.0f) * this.screenShake; this.screenShake += (0.0f - this.screenShake) * 0.2f * Time.TimeMult; // Remove old screen shake camTransform.Pos -= lastScreenShakeOffset; camTransform.Angle -= lastScreenShakeAngle; // Remove disposed / null follow targets this.followTargets.RemoveAll(obj => obj == null || obj.Disposed); // Follow a group of objects behavior if (this.followTargets.Count > 0) { // Determine the position to focus on. It's the average of all follow object positions. this.focusPos = Vector3.Zero; foreach (Transform obj in this.followTargets) { this.focusPos += obj.Pos; } this.focusPos /= this.followTargets.Count; // Determine how far these objects are away from each other this.focusRadius = 0.0f; foreach (Transform obj in this.followTargets) { this.focusRadius = MathF.Max((obj.Pos - this.focusPos).Length, this.focusRadius); } // Move the camera so it can most likely see all of the required objects Vector3 targetPos = this.focusPos + this.GetTargetOffset(this.focusRadius); Vector3 posDiff = (targetPos - camTransform.Pos); Vector3 targetVelocity = posDiff * 0.1f * MathF.Pow(2.0f, -this.smoothness); camTransform.MoveByAbs(targetVelocity * Time.TimeMult); microTransform.MoveToAbs(new Vector3(camTransform.Pos.Xy)); } // Apply new screen shake camTransform.Pos += this.screenShakeOffset; camTransform.Angle += this.screenShakeAngle; }
void ICmpUpdatable.OnUpdate() { Transform transform = this.GameObj.Transform; Camera camera = this.GameObj.GetComponent <Camera>(); // The position to focus on. Vector3 focusPos = this.targetFocusPos; // The position where the camera itself should move Vector3 targetPos = focusPos - new Vector3(0.0f, 0.0f, camera.FocusDist); // A relative movement vector that would place the camera directly at its target position. Vector3 posDiff = (targetPos - transform.Pos); // A relative movement vector that doesn't go all the way, but just a bit towards its target. Vector3 targetVelocity = posDiff * 0.1f * MathF.Pow(2.0f, -this.smoothness); // Move the camera transform.MoveByAbs(targetVelocity * Time.TimeMult); }
void ICmpUpdatable.OnUpdate() { if (this.followTarget == null) { return; } Transform transform = this.GameObj.Transform; Camera camera = this.GameObj.GetComponent <Camera>(); // Determine where the camera should be and smoothly move it towards that position Vector3 targetPos = this.followTarget.Pos - new Vector3(0.0f, 0.0f, camera.FocusDist); Vector3 posDiff = (targetPos - transform.Pos); Vector3 targetVelocity = posDiff * MathF.Pow(2.0f, -this.smoothness); transform.MoveByAbs(targetVelocity * Time.TimeMult); }