static void FOVTransition(float fov, long intermission = 0) { startFOV = currentFOV; endFOV = Alg.Clamp(10, fov, 160); startFOVTime = GameTime.Ticks; endFOVTime = startFOVTime + intermission; }
public override void Update(GuidedVob vob, long now) { if (Target == null) { return; } if (!Cast.Try(vob.ScriptObject, out NPCInst npc)) { throw new Exception("Vob used with GoToVobLookAtCommand is no NPC!"); } if (npc.IsDead) { return; } var gNpc = npc.BaseInst.gVob; gNpc.RbtTimer = 500; gNpc.RbtTargetVob = Target.BaseInst.gVob; gNpc.RbtBitfield = gNpc.RbtBitfield | (1 << 4); // stand when reached Target.GetPosition().SetGVec(gNpc.RbtTargetPos); gNpc.RbtMaxTargetDist = Distance * Distance; gNpc.RbtGotoFollowPosition(); Vec3f npcPos = npc.GetPosition(); Vec3f targetPos = Target.GetPosition(); if (npcPos.GetDistance(targetPos) <= Distance) { const float maxTurnFightSpeed = 0.08f; float bestYaw = Angles.GetYawFromAtVector(targetPos - npcPos); Angles curAngles = npc.GetAngles(); float yawDiff = Angles.Difference(bestYaw, curAngles.Yaw); curAngles.Yaw += Alg.Clamp(-maxTurnFightSpeed, yawDiff, maxTurnFightSpeed); npc.SetAngles(curAngles); } }
void LookAround(NPCInst hero) { const float maxLookSpeed = 2f; float rotSpeed = 0; if (InputHandler.MouseDistY != 0) { rotSpeed = Alg.Clamp(-maxLookSpeed, InputHandler.MouseDistY * 0.35f * MouseSpeed, maxLookSpeed); var cam = zCAICamera.CurrentCam; cam.BestElevation = Alg.Clamp(-50, cam.BestElevation + rotSpeed, 85); } if (InputHandler.MouseDistX != 0) { rotSpeed = Alg.Clamp(-maxLookSpeed, InputHandler.MouseDistX * 0.35f * MouseSpeed, maxLookSpeed); var cam = zCAICamera.CurrentCam; cam.BestAzimuth -= rotSpeed; } }
static void CheckCombineAim(NPCInst hero, Vec3f direction) { var gModel = hero.BaseInst.gModel; int aniID; if (gModel.IsAnimationActive("S_BOWAIM")) { aniID = gModel.GetAniIDFromAniName("S_BOWAIM"); } else if (gModel.IsAnimationActive("S_CBOWAIM")) { aniID = gModel.GetAniIDFromAniName("S_CBOWAIM"); } else { if (freeAim) { crosshair.Hide(); } return; } if (freeAim) { crosshair.Show(); } Angles heroAngles = hero.GetAngles(); Angles angles = Angles.FromAtVector(direction); float pitch = Angles.Difference(angles.Pitch, heroAngles.Pitch); float yaw = Angles.Difference(angles.Yaw, heroAngles.Yaw); float x = 0.6f;// Alg.Clamp(0, 0.5f - yaw / Angles.PI, 1); float y = Alg.Clamp(0, 0.47f - (pitch < 0 ? 1.2f : 1.0f) * pitch / Angles.PI, 1); hero.BaseInst.gAI.InterpolateCombineAni(x, y, aniID); }
static void FreeAiming(NPCInst hero) { if (InputHandler.MouseDistY != 0) { const float maxSpeed = 1.0f; float rotSpeed = Alg.Clamp(-maxSpeed, InputHandler.MouseDistY * 0.16f * MouseSpeed, maxSpeed); var cam = zCAICamera.CurrentCam; cam.BestElevation = Alg.Clamp(-65, cam.BestElevation + rotSpeed, 85); } if (InputHandler.MouseDistX != 0) { const float maxSpeed = 1.2f; float rotSpeed = Alg.Clamp(-maxSpeed, InputHandler.MouseDistX * 0.20f * MouseSpeed, maxSpeed); hero.BaseInst.gAI.Turn(rotSpeed, false); } CalcRangedTrace(hero, out Vec3f start, out Vec3f end); crosshair.SetTarget(end); CheckCombineAim(hero, (Vec3f)GothicGlobals.Game.GetCameraVob().Direction); }
static void DoTurning(NPCInst hero) { if (hero.BaseInst.gAI.GetFoundLedge()) { return; } const float maxTurnFightSpeed = 0.07f; NPCInst enemy = PlayerFocus.LockedTarget; if (enemy != null) { Vec3f heroPos = hero.GetPosition(); Vec3f enemyPos = enemy.GetPosition(); float bestYaw = Angles.GetYawFromAtVector(enemyPos - heroPos); Angles curAngles = hero.GetAngles(); float yawDiff = Angles.Difference(bestYaw, curAngles.Yaw); curAngles.Yaw += Alg.Clamp(-maxTurnFightSpeed, yawDiff, maxTurnFightSpeed); hero.SetAngles(curAngles); CheckCombineAim(hero, enemyPos - heroPos); return; } const float maxLookupSpeed = 2f; float rotSpeed = 0; if (InputHandler.MouseDistY != 0) { rotSpeed = Alg.Clamp(-maxLookupSpeed, InputHandler.MouseDistY * 0.35f * MouseSpeed, maxLookupSpeed); if (hero.Environment.WaterLevel >= 1) { hero.BaseInst.gAI.DiveRotateX(rotSpeed); } else { var cam = zCAICamera.CurrentCam; cam.BestElevation = Alg.Clamp(-50, cam.BestElevation + rotSpeed, 85); } } // Fixme: do own turning const float maxTurnSpeed = 2f; if (!KeyBind.Action.IsPressed()) { float turn = 0; if (KeyBind.TurnLeft.IsPressed()) { turn = -maxTurnSpeed; } else if (KeyBind.TurnRight.IsPressed()) { turn = maxTurnSpeed; } else if (Math.Abs(InputHandler.MouseDistX) > ((rotSpeed > 0.5f && hero.Movement == NPCMovement.Stand) ? 18 : 2)) { turn = Alg.Clamp(-maxTurnSpeed, InputHandler.MouseDistX * 0.45f * MouseSpeed, maxTurnSpeed); } if (turn != 0) { hero.BaseInst.gAI.Turn(turn, !hero.ModelInst.IsInAnimation()); return; } } hero.BaseInst.gVob.AniCtrl.StopTurnAnis(); }