public void AddLeaf(ColliderKey key, ref ChildCollider leaf) { MTransform worldFromLeafA = Mul(m_WorldFromA, new MTransform(leaf.TransformFromChild)); ConvexComposite( m_Context, m_KeyPath.GetLeafKey(key), leaf.Collider, m_CompositeColliderB, worldFromLeafA, m_WorldFromB, m_Expansion, m_Flipped); }
// Tests that a contact point is on the surface of its shape static unsafe void CheckPointOnSurface(ref ChildCollider leaf, float3 position, string failureMessage) { float3 positionLocal = math.transform(math.inverse(leaf.TransformFromChild), position); leaf.Collider->CalculateDistance(new PointDistanceInput { Position = positionLocal, MaxDistance = float.MaxValue, Filter = Physics.CollisionFilter.Default }, out DistanceHit hit); Assert.Less(hit.Distance, tolerance, failureMessage + ": contact point outside of shape"); Assert.Greater(hit.Distance, -((ConvexCollider *)leaf.Collider)->ConvexHull.ConvexRadius - tolerance, failureMessage + ": contact point inside of shape"); }
public void CollisionDetectedInvisWall(ChildCollider childScript) { if (childScript.name == "Right") { dir = false; } else if (childScript.name == "Left") { dir = true; } }
void OnInteractionTriggerExit(ChildCollider callingChildCollider, Collider other) { BaseInteraction interactable = other.gameObject.GetComponent <BaseInteraction>(); if (interactable) { overlappingInteractables.Remove(other); if (overlappingInteractables.Count <= 0 && selectedInteractable) { selectedInteractable.OnDeselected(); selectedInteractable = null; } } }
/// <summary> /// Given the root Collider of a hierarchy and a ColliderKey referencing a child in that hierarchy, /// this function returns the ChildCollider requested. /// </summary> /// <param name="rootColliderPtr">A <see cref="Collider"/> at the root of a Collider hierarchy.</param> /// <param name="childColliderKey">A <see cref="ColliderKey"/> referencing a child Collider somewhere in the hierarchy below rootColliderPtr.</param> /// <param name="childCollider">A valid <see cref="ChildCollider"/> returned from the hierarchy, if found.</param> /// <returns>Whether a specified ColliderKey was successfully found in the hierarchy.</returns> public static unsafe bool TryGetChildInHierarchy(Collider *rootColliderPtr, ColliderKey childColliderKey, out ChildCollider childCollider) { //public static unsafe bool GetLeafCollider(Collider* root, RigidTransform rootTransform, ColliderKey key, out ChildCollider leaf) childCollider = new ChildCollider(rootColliderPtr, RigidTransform.identity); while (!childColliderKey.Equals(ColliderKey.Empty)) { if (!childCollider.Collider->GetChild(ref childColliderKey, out ChildCollider child)) { break; } childCollider = new ChildCollider(childCollider, child); } return(childCollider.Collider != null); }
public bool GetChild(ref ColliderKey key, out ChildCollider child) { if (key.PopSubKey(NumColliderKeyBits, out uint subKey)) { var index = new int2(((int)subKey >> 1) & ((1 << (int)Terrain.NumXBits) - 1), (int)subKey >> ((int)Terrain.NumXBits + 1)); int triangle = (int)subKey & 1; child = Terrain.GetTriangle(index, triangle, Filter, Material); return(true); } else { child = new ChildCollider(); return(false); } }
void OnInteractionTriggerEnter(ChildCollider callingChildCollider, Collider other) { BaseInteraction interactable = other.gameObject.GetComponent <BaseInteraction>(); if (interactable) { overlappingInteractables.Add(other); if (overlappingInteractables.Count < 2) { selectedInteractable = interactable; selectedInteractable.OnSelected(); } } return; }
public void GetLeaves <T>(ref T collector) where T : struct, ILeafColliderCollector { for (int x = 0; x < Terrain.Size.x - 1; x++) { for (int y = 0; y < Terrain.Size.y - 1; y++) { var index = new int2(x, y); for (int iTriangle = 0; iTriangle < 2; iTriangle++) { ColliderKey key = Terrain.GetColliderKey(index, iTriangle); ChildCollider leaf = Terrain.GetTriangle(index, iTriangle, Filter, Material); collector.AddLeaf(key, ref leaf); } } } }
public void CollisionDetected(ChildCollider childScript) { print("child collided: " + childScript.name); if ((childScript.name == "Right" && childScript.name != "Left")) { dir = false; } else if (childScript.name != "Right" && childScript.name == "Left") { dir = true; } else if (childScript.name == "Right" && childScript.name == "Left") { Debug.Log("Stuck"); } }
void Start() { // Grab refs if (!ownerCharacterController) { ownerCharacterController = GetComponent <CharacterController>(); } if (!ownerCamera) { ownerCamera = Camera.main; } // Find child interaction collider if we have none if (!interactionCollider) { interactionCollider = GetComponentInChildren <ChildCollider>(); if (interactionCollider) { Rigidbody interactionColliderRigidBody = interactionCollider.gameObject.GetComponent <Rigidbody>(); if (!interactionColliderRigidBody) { interactionColliderRigidBody = interactionCollider.gameObject.AddComponent <Rigidbody>(); } if (interactionColliderRigidBody) { interactionColliderRigidBody.isKinematic = true; interactionColliderRigidBody.useGravity = false; } } } if (interactionCollider) { interactionCollider.onChildTriggerEnter += OnInteractionTriggerEnter; interactionCollider.onChildTriggerExit += OnInteractionTriggerExit; } if (!characterAnimator) { characterAnimator = GetComponentInChildren <Animator>(); } // Initialize lists overlappingInteractables = new List <Collider>(); }
public bool GetLeaf(ColliderKey key, out ChildCollider leaf) { return(GetChild(ref key, out leaf)); // all children of TerrainCollider are leaves }
static unsafe void GetHitLeaf(ref Physics.PhysicsWorld world, int rigidBodyIndex, ColliderKey colliderKey, MTransform queryFromWorld, out ChildCollider leaf, out MTransform queryFromTarget) { Physics.RigidBody body = world.Bodies[rigidBodyIndex]; Collider.GetLeafCollider(body.Collider, body.WorldFromBody, colliderKey, out leaf); MTransform worldFromLeaf = new MTransform(leaf.TransformFromChild); queryFromTarget = Math.Mul(queryFromWorld, worldFromLeaf); }
private void FindTarget() { //if(this.target!=null) //Debug.Log(this.target); Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); //检测结果 RaycastHit hitInfo; Physics2D.queriesStartInColliders = false; //避免检测到自己 //Debug.Log(Camera.main.ScreenToWorldPoint(Input.mousePosition)); //Debug.DrawRay(Camera.main.ScreenToWorldPoint(Input.mousePosition), new Quaternion(0, 0, -1, 0) * gameObject.transform.up.normalized * 0.3f, Color.black); Debug.DrawRay(ray.origin, ray.direction * 50f, Color.black); //hits = Physics2D.RaycastAll(ray.origin,new Vector3(0,0,50),50f,1<<LayerMask.NameToLayer("Terrain")); Physics.Raycast(ray, out hitInfo, 200, 1 << LayerMask.NameToLayer("CursorCollider")); if (hitInfo.collider != null) { if (hitInfo.collider.gameObject.GetComponent <ChildCollider>() != null) { ChildCollider cCollider = hitInfo.collider.gameObject.GetComponent <ChildCollider>(); if (cCollider.father.GetComponent <Animator>().GetBool("dead") == false) //且不为死亡状态 { cCollider.SetKillCursor(); this.target = cCollider.father.GetComponent <humanBody>(); return; } } else { Debug.Log("判定失败"); } //Debug.Log(hitInfo); //Debug.Log(hit.collider.gameObject.name);//打印鼠标点击到的物体名称 //Debug.Log(LayerMask.NameToLayer("")); //Debug.Log("鼠标检测到敌人"); } //此时表示鼠标移出了物体,物体原有的预约图案变没 if (this.target != null && this.target.tenetDirection == 1) { //Debug.Log("改回来"); ChildCollider cCollider = this.target.gameObject.transform.Find("CursorCollider").GetComponent <ChildCollider>(); cCollider.SetDefaultCursor(); } this.target = null; }
public override void OnChildTriggerExit(ChildCollider P_child, Collider P_other) { }
// protected void FixedUpdate () // { // F_helper = transform.position; // F_helper.z -= 1; // Debug.DrawLine(F_helper, Destination, Color.cyan); // if (GainHeightWaypoint != Vector3.zero) { // Destination = GainHeightWaypoint; // if ((GainHeightWaypoint - transform.position).sqrMagnitude <= 1.5f) { // if (Vector3.Dot(transform.forward, (myTarget.transform.position - transform.position).normalized) < 0f) { // GainHeightWaypoint = GainHeightWaypoint + (transform.right * 30f); // } else { // GainHeightWaypoint = Vector3.zero; // } // } // } else { // Destination = myTarget.transform.position; // } // // // // //beware, rigidbody.velocity has a gravitation calculation right before fixedupdate // //means there is already an applied force down the gravitation, that we have to outsmart with speed against gravitation // Vector3 velocity = GravitationForce; // if (StartOfFalling != Vector3.zero) { // // } // // Debug.DrawRay(transform.position, Vector3.up * GravitationForce.y, Color.red); // // float F_groundHeight = 0f; // if (Physics.Raycast(transform.position, -Vector3.up, out _heightHitter, MaxHeight, LayerUtils.GroundMask)) { // F_groundHeight = _heightHitter.distance; // } // // if ((transform.position.y-WippingFactor) > Destination.y) { // Force.y -= AccelerationUp * Time.deltaTime * 0.5f; // Vector3 beforeChange = velocity + Force; // if ((transform.position.y + beforeChange.y) < Destination.y) { // Force.y = Mathf.SmoothDamp(Force.y, -GravitationForce.y, ref currentVelocity, Time.deltaTime * AccelerationUp); // } // // if (WippingUp) { // // WippingUp = false; // // WippingFactor = -MaxWippingFactor; // // } // } else if ((transform.position.y-WippingFactor) < Destination.y) { // Force.y += AccelerationUp * Time.deltaTime; // Vector3 beforeChange = velocity + Force; // if ((transform.position.y + beforeChange.y) > Destination.y) { // Force.y = Mathf.SmoothDamp(Force.y, -GravitationForce.y, ref currentVelocity, Time.deltaTime * AccelerationUp); // } // // if (!WippingUp) { // // WippingUp = true; // // WippingFactor = MaxWippingFactor; // // } // } // // // if ((Destination - transform.position).sqrMagnitude <= 1.2f) { // Destination = myTarget.transform.position; // // } // // Debug.DrawRay(transform.position, Vector3.up * Force.y, Color.yellow); // velocity.y += Force.y; // // if ((F_groundHeight-(Lifesize.y*0.5f)) <= 0.1f && velocity.y <= 0f) { // velocity.y = 0f; // } // rigidbody.velocity = velocity; // // if (velocity.y < 0f) { // if (StartOfFalling == Vector3.zero) { // StartOfFalling = transform.position; // } // } else { // StartOfFalling = Vector3.zero; // } // } public override void OnChildTriggerEnter(ChildCollider P_child, Collider P_other) { if (P_child.ColliderID == 0) { //main collider } else if (P_child.ColliderID == 1) { //Vision-Collider if (P_other.gameObject.tag == "floor") { FlyingUnitState.Instance.GainHeight(this); } else { BasicLifeform F_life = GameObjectHelper.getLifeform(P_other.gameObject.transform); FlyingUnitState.Instance.AvoidObstacle(this, F_life, P_other); } } }