public static bool Raycast(float time, Vector3 origin, Vector3 direction, List <RewinderHitboxHit> result) { time = GetTime() - time; RewinderSnapshot snapshot = Find(time); if (snapshot != null) { snapshot.Raycast(origin, direction, result); } return(result.Count > 0); }
public override void Fire() { PhotonNetwork.Instantiate(this.ammo.ammoResourceName, this.bulletOrigin.position, bulletOrigin.transform.rotation, 0); if (photonView.isMine) { Ray r = new Ray(bulletOrigin.position, bulletOrigin.forward); List <RewinderHitboxHit> hits = new List <RewinderHitboxHit>(); RewinderSnapshot.Raycast(Time.time, r.origin, r.direction, out hits); if (hits.Count > 0) { FireOnHit(hits); } } }
void Update() { if (Application.isPlaying && RewinderSnapshot.Count > 0) { RewinderSnapshot snapshot = RewinderSnapshot.Find(Time.time - behind); if (snapshot != null) { accuracy = (float)System.Math.Round(Mathf.Abs((Time.time - behind) - snapshot.Time), 3); RewinderHitboxGroupSnapshot group = snapshot.Groups.First(); // On first time, setup debug display #if REWINDER_DEBUG if (debugDict.Count == 0) { foreach (RewinderHitbox hitbox in group.Group.BodyHitboxes) { switch (hitbox.ColliderType) { case RewinderColliderType.Sphere: { GameObject go = GameObject.CreatePrimitive(PrimitiveType.Sphere); go.renderer.material = Resources.Load("RewinderDebug", typeof(Material)) as Material; go.transform.localScale = hitbox.Collider.bounds.size; debugDict.Add(hitbox, go); } break; case RewinderColliderType.Box: { GameObject go = GameObject.CreatePrimitive(PrimitiveType.Cube); go.transform.localScale = hitbox.Bounds.size; go.renderer.material = Resources.Load("RewinderDebug", typeof(Material)) as Material; debugDict.Add(hitbox, go); } break; } } } // Move debug display for (int i = 0; i < group.HitboxMatrices_Debug.Length; ++i) { Matrix4x4 m = group.HitboxMatrices_Debug[i]; RewinderHitbox hitbox = group.Group.BodyHitboxes[i]; GameObject go = debugDict[hitbox]; go.transform.position = m.MultiplyPoint(Vector3.zero); go.transform.rotation = group.HitboxRotations_Debug[i]; } #endif // Do collision detection (if any) if (Input.GetMouseButtonDown(0)) { RaycastHit rHit; Ray r = Camera.main.ScreenPointToRay(Input.mousePosition); System.Diagnostics.Stopwatch sw = null; switch (selected) { case 0: { List <RewinderHitboxHit> hits; // Time how long the raycast takes sw = System.Diagnostics.Stopwatch.StartNew(); RewinderSnapshot.Raycast(behind, r.origin, r.direction, out hits); sw.Stop(); hit = hits.FirstOrDefault(); RewinderSnapshot.Recycle(hits); sphereExample.active = false; } break; case 1: if (Physics.Raycast(r, out rHit, 1024f, 1 << 8)) { drawPosition = rHit.point; List <RewinderHitboxHit> hits; // Time how long the overlap takes sw = System.Diagnostics.Stopwatch.StartNew(); RewinderSnapshot.OverlapSphere(behind, drawPosition, 0.5f, out hits); sw.Stop(); hit = hits.FirstOrDefault(); RewinderSnapshot.Recycle(hits); sphereExample.transform.position = drawPosition; sphereExample.active = true; } break; } sw.Stop(); time = (float)((double)sw.ElapsedTicks / (double)System.Diagnostics.Stopwatch.Frequency); } } } }