From c3ca564cfc91c4288af57a533e91d08aa864a44c Mon Sep 17 00:00:00 2001 From: "Dileep V. Reddy" Date: Tue, 30 Jan 2024 06:44:54 -0700 Subject: [PATCH] Minor addition toe SpectatorCamera. Added three chase modes to lazy follow. 0: Catch up until tracer is centered again. 1: Same but don't move if tracer isn't moving (camera moving when character is not is jarring). 2: Stop chasing if tracer is closer than lagdistance. Game modes benefit from a 'center camera' button but that doesn't have to be hard-baked into the engine. --- wadsrc/static/zscript/actors/shared/camera.zs | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/wadsrc/static/zscript/actors/shared/camera.zs b/wadsrc/static/zscript/actors/shared/camera.zs index 8005e7ca34..0e35a5efbd 100644 --- a/wadsrc/static/zscript/actors/shared/camera.zs +++ b/wadsrc/static/zscript/actors/shared/camera.zs @@ -132,10 +132,12 @@ class AimingCamera : SecurityCamera class SpectatorCamera : Actor { - double lagdistance; - bool chasing_tracer; + bool chasingtracer; + double lagdistance; // camera gives chase (lazy follow) if tracer gets > lagdistance away from camera.pos + int chasemode; // 0: chase until tracer centered, 1: same but only when tracer is moving, 2: stop chase if tracer within lagdistance property lagdistance : lagdistance; - property chasing_tracer : chasing_tracer; + property chasingtracer : chasingtracer; + property chasemode : chasemode; default { @@ -145,8 +147,9 @@ class SpectatorCamera : Actor +NOINTERACTION RenderStyle "None"; CameraHeight 0; - SpectatorCamera.chasing_tracer false; + SpectatorCamera.chasingtracer false; SpectatorCamera.lagdistance 0.0; + SpectatorCamera.chasemode 0; } void Init(double dist, double yaw, double inpitch, int inflags) @@ -181,25 +184,26 @@ class SpectatorCamera : Actor { Vector3 distvec = tracer.pos - pos; double dist = distvec.length(); - if((dist <= 4 && chasing_tracer) || lagdistance <= 0.0) // Keep tracer centered on screen + if((dist <= 4 && chasingtracer) || lagdistance <= 0.0) // Keep tracer centered on screen { SetOrigin(tracer.pos, true); - chasing_tracer = false; + chasingtracer = false; } else // Lazy follow tracer { if(dist >= 2*lagdistance) { SetOrigin(tracer.pos, true); - chasing_tracer = false; + chasingtracer = false; } - else if(dist > lagdistance && !chasing_tracer) chasing_tracer = true; + else if(dist > lagdistance && !chasingtracer) chasingtracer = true; - if(chasing_tracer) + if(chasingtracer) { speed = tracer.vel.xy.length()/dist; - if(speed == 0.0) speed = tracer.speed/dist; + if((speed == 0.0) && (chasemode == 0)) speed = tracer.speed/dist; SetOrigin(pos + 2*distvec*speed, true); + if(chasemode > 1) chasingtracer = false; } } }