// Use this for initialization public void Init() { ChecksumExtractor.Init(this); gameObjectMap = new Dictionary <IBody, GameObject>(); collisionInfo = new Dictionary <RigidBody, Dictionary <RigidBody, TSCollision> >(); behavioursMap = new Dictionary <IBody, HashList <TrueSyncBehaviour> >(); transformMap = new Dictionary <IBody, TSTransform>(); hit = new TSRaycastHit(); CollisionSystemPersistentSAP collisionSystem = new CollisionSystemPersistentSAP(); collisionSystem.EnableSpeculativeContacts = SpeculativeContacts; world = new World(collisionSystem); collisionSystem.world = world; world.physicsManager = this; world.Gravity = Gravity; world.Events.BodiesBeginCollide += CollisionEnter; world.Events.BodiesStayCollide += CollisionStay; world.Events.BodiesEndCollide += CollisionExit; world.Events.TriggerBeginCollide += TriggerEnter; world.Events.TriggerStayCollide += TriggerStay; world.Events.TriggerEndCollide += TriggerExit; world.Events.RemovedRigidBody += OnRemovedRigidBody; instance = this; AddRigidBodies(); }
public int RaycastAll(TSVector rayOrigin, TSVector rayDirection, FP maxDistance, out TSRaycastHit[] hits, int layerMask) { List <TSRaycastHit> raycastHits = new List <TSRaycastHit>(); var direction = rayDirection; direction *= maxDistance; var d = TSVector.Distance(rayOrigin, rayOrigin + direction); world.CollisionSystem.RaycastAll(rayOrigin, direction, (b, n, f) => { //UnityEngine.Debug.LogWarning($"{maxDistance} , {f}"); GameObject other = PhysicsManager.instance.GetGameObject(b); TSRigidBody bodyComponent = other.GetComponent <TSRigidBody>(); TSCollider colliderComponent = other.GetComponent <TSCollider>(); TSTransform transformComponent = other.GetComponent <TSTransform>(); var hit = new TSRaycastHit(bodyComponent, colliderComponent, transformComponent, n, rayOrigin, direction, f); var tmp = TSVector.Distance(hit.point, rayOrigin); Debug.LogWarning($"碰撞的距离{tmp},最大距离{d}"); if (tmp <= d) { raycastHits.Add(hit); } return(true); }, layerMask); hits = raycastHits.ToArray(); return(hits.Length); }
public static bool Raycast(TSVector rayOrigin, TSVector rayDirection, out TSRaycastHit hit, FP maxDistance, int layerMask = UnityEngine.Physics.DefaultRaycastLayers) { TSRay ray = new TSRay(rayOrigin, direction: rayDirection); hit = PhysicsWorldManager.instance.Raycast(ray, maxDistance, layerMask: layerMask); if (hit != null) { if (hit.distance <= maxDistance) { return(true); } } return(false); }
public static bool Raycast(TSVector rayOrigin, TSVector rayDirection, out TSRaycastHit hit, FP maxDistance, int layerMask = UnityEngine.Physics.DefaultRaycastLayers) { hit = null; if (rayDirection.x == FP.Zero && rayDirection.y == FP.Zero && rayDirection.z == FP.Zero) { return(false); } ray.origin = rayOrigin; ray.direction = rayDirection; hit = PhysicsWorldManager.instance.Raycast(ray, maxDistance, layerMask: layerMask); if (hit != null) { if (hit.distance <= maxDistance) { return(true); } } return(false); }