private void Fire() { //convert ping to float seconds var ping = (BasePingMs + Random.Range(0, PingRandomMs)) / 1000f; using (TimePhysics.RewindSeconds(ping, HitboxBody)) { Ray ray = new Ray(RayOrigin.transform.position, RayOrigin.transform.forward * ShootDistance); RaycastHit hit; Debug.DrawRay(ray.origin, ray.direction, ShotColor); if (TimePhysics.SphereCast(ray, SphereRadius, out hit, ShootDistance)) { var marker = hit.collider.GetComponent <HitboxMarkerDebug>(); if (marker != null && TimePhysics.DebugMode) { ShooterDebug?.DebugHitRewind(marker, 2f); } } } }
private void ExecuteCommand(Command cmd) { if (!cmd.Rewind) // don't rewind if we don't have to { return; } var ping = Random.Range(Ping - PingJitter, Ping + PingJitter); Profiler.BeginSample("Rewind & Cast"); using (TimePhysics.RewindSeconds(ping)) // or using (TimePhysics.RewindFrames(FrameDelay)) { //perform all raycasts for this rewindframe within the 'using' block if (cmd.Primary) { //Shoot(cmd.Ray, Distance); Spherecast(cmd.Ray, .25f, Distance); } if (cmd.Secondary) { AOE(cmd.Ray.origin, 10f, Distance); } } Profiler.EndSample(); }