void OnTriggerExit(Collider other) { if (!MalbersTools.CollidersLayer(other, _StepsManager.GroundLayer)) { return; //Ignore layers that are not Ground } hastrack = false; // if the feet is on the air then can put a track }
void OnTriggerEnter(Collider other) { if (!MalbersTools.CollidersLayer(other, LayerMask.GetMask("Animal"))) { return; //Just accept animal layer only } if (HeadOnly && !other.name.ToLower().Contains("head")) { return; //If is Head Only and no head was found Skip } Animal newAnimal = other.GetComponentInParent <Animal>(); //Get the animal on the entering collider if (!newAnimal) { return; //If there's no animal do nothing } newAnimal.ActionID = ID; //Set the ID on the ANIMAL that entered the Action if (animal_Colliders.Find(coll => coll == other) == null) //if the entering collider is not already on the list add it { animal_Colliders.Add(other); } if (newAnimal == oldAnimal) { return; //if the animal is the same do nothing (when entering two animals on the same Zone) } else { if (oldAnimal) { oldAnimal.ActionID = -1; //Remove the old animal and remove the Action ID animal_Colliders = new List <Collider>(); //Clean the colliders } oldAnimal = newAnimal; //Set a new Animal // if (animalProxy) animalProxy.SetAnimal(newAnimal); //Set to the Proxy the current animal entering the zone } newAnimal.OnAction.AddListener(OnActionListener); //Listen when the animal activate the Action Input OnEnter.Invoke(newAnimal); if (automatic) //Just activate when is on the Locomotion State if this is automatic { if (newAnimal.AnimState == AnimTag.Jump && !ActiveOnJump) { return; //Dont start an automatic action if is jumping and active on jump is disabled } // newAnimal.OnAction.RemoveListener(OnActionListener); newAnimal.SetAction(ID); StartCoroutine(ReEnable(newAnimal)); } }
void OnTriggerEnter(Collider other) { if (_StepsManager == null) { return; } if (!MalbersTools.CollidersLayer(other, _StepsManager.GroundLayer.Value)) { return; //Ignore layers that are not Ground } if (!waitrack) { StartCoroutine(WaitForStep()); //Wait Half a Second before making another Step _StepsManager.EnterStep(this); HasTrack = true; } }
void OnTriggerEnter(Collider other) { if (other.isTrigger) { return; } if (!MalbersTools.CollidersLayer(other, LayerMask.GetMask("Animal"))) { return; //Just accept animal layer only } if (HeadOnly && !other.name.Contains(HeadName)) { return; //If is Head Only and no head was found Skip } MAnimal newAnimal = other.GetComponentInParent <MAnimal>(); //Get the animal on the entering collider if (!newAnimal) { return; //If there's no animal do nothing } if (animal_Colliders.Find(coll => coll == other) == null) //if the entering collider is not already on the list add it { animal_Colliders.Add(other); } if (newAnimal == CurrentAnimal) { return; //if the animal is the same do nothing (when entering two animals on the same Zone) } else { if (CurrentAnimal) { animal_Colliders = new List <Collider>(); //Clean the colliders } CurrentAnimal = newAnimal; //Set a new Animal AnimalStats = CurrentAnimal.GetComponentInParent <Stats>(); StatModifierOnEnter.ModifyStat(AnimalStats); //Modify the stats when exit OnEnter.Invoke(CurrentAnimal); ActivateZone(); } }
private void LateUpdate() { float targetDist = m_OriginalDist; // initially set the target distance m_Ray.origin = m_Pivot.position + m_Pivot.forward * sphereCastRadius; m_Ray.direction = -m_Pivot.forward; var cols = Physics.OverlapSphere(m_Ray.origin, sphereCastRadius); // initial check to see if start of spherecast intersects anything bool initialIntersect = false; bool hitSomething = false; for (int i = 0; i < cols.Length; i++) // loop through all the collisions to check if something we care about { if ((!cols[i].isTrigger) && !(MalbersTools.CollidersLayer(cols[i], dontClip))) //is on a layer we don't want to clip { initialIntersect = true; break; } } if (initialIntersect) // if there is a collision { m_Ray.origin += m_Pivot.forward * sphereCastRadius; hits = Physics.RaycastAll(m_Ray, m_OriginalDist - sphereCastRadius); // do a raycast and gather all the intersections } else // if there was no collision do a sphere cast to see if there were any other collisions { hits = Physics.SphereCastAll(m_Ray, sphereCastRadius, m_OriginalDist + sphereCastRadius); } Array.Sort(hits, m_RayHitComparer); // sort the collisions by distance float nearest = Mathf.Infinity; // set the variable used for storing the closest to be as far as possible for (int i = 0; i < hits.Length; i++) // loop through all the collisions { // only deal with the collision if it was closer than the previous one, not a trigger, not in the Layer Mask if (hits[i].distance < nearest && (!hits[i].collider.isTrigger) && !MalbersTools.CollidersLayer(hits[i].collider, dontClip)) { nearest = hits[i].distance; // change the nearest collision to latest targetDist = -m_Pivot.InverseTransformPoint(hits[i].point).z; hitSomething = true; } } if (hitSomething) // visualise the cam clip effect in the editor { Debug.DrawRay(m_Ray.origin, -m_Pivot.forward * (targetDist + sphereCastRadius), Color.red); } // hit something so move the camera to a better position protecting = hitSomething; m_CurrentDist = Mathf.SmoothDamp(m_CurrentDist, targetDist, ref m_MoveVelocity, m_CurrentDist > targetDist ? clipMoveTime : returnTime); m_CurrentDist = Mathf.Clamp(m_CurrentDist, closestDistance, m_OriginalDist); m_Cam.localPosition = -Vector3.forward * m_CurrentDist; }