how to force a trigger to detect enemy not moving

hi is this a way to force a trigger to detect an object in x time??
something like a predefined function in unity.

This question isn’t clear. There are trigger events to detect when an object enters the trigger (OnTriggerEnter), exits the trigger (OnTriggerExit) or to be fired while the object is inside the trigger (OnTriggerStay - sent each physics cycle).

If the trigger is static, it will detect moving rigidbodies or CharacterControllers that enter it. If the trigger moves and the object is static, add a kinematic rigidbody to the trigger.

i want trigger detect a no-moving character controller so i want a function that force detecting in the time i want.

Hmm, still not very clear but perhaps something like this:

private var wasStoppedSinceNow : float; //Typecast as a float so you can increase by decimal increments if you want
private var timeToStop : float = 5;
private var rate : float = 1;

function OnTriggerStay (hit : Collider) {
	var targetHit : GameObject = hit.collider.gameObject;
	if (targetHit.tag == "enemy" && wasStoppedSinceNow >= timeToStop) {
		if (targetHit.GetComponent("CharacterMotor").movement.velocity == Vector3.zero) {
			//Do whatever you want to do here and then once your function is finished
			wasStoppedSinceNow = 0;
		}
	} else if (wasStoppedSinceNow < timeToStop) {
		wasStoppedSinceNow += Time.deltaTime * rate;
	}
}

I’m not even sure if this will work, let alone if this is what you want.

EDIT:


Changed the script to account for time … haven’t tested so it won’t be perfect … I’d say your question is probably too generalised and unspecific to generate a perfect response anyway, but whatever.

Hope that helps, Klep