- Home /
OnTriggerStay only happens when I move?(c#)
I'm having problems where instead of "every frame" my updating for certain things is only happening when I move. For instance:
void OnTriggerStay(Collider col)
{
if(col.tag == "player")
{
tooltips.text = "Weapon type: " + currentWepType + "\n Weapon damage: " + dmg.ToString() + "\n Attack speed: " + aspd + " attacks per second";
}
}
and
if(col.tag == "weaponEquipped")
{
wepDmg = col.GetComponent<Item>().dmg + Mathf.FloorToInt(skillDisplay);
wepSpd = col.GetComponent<Item>().aspd;
if(col.GetComponent<Item>().currentWepType == "1h sword")
{
currentWeaponType = "1h sword";
skillType = "swordSkill";
skillDisplay = swordSkill;
}
else if(col.GetComponent<Item>().currentWepType == "2h sword")
{
currentWeaponType = "2h sword";
skillType = "twoHandSwordSkill";
skillDisplay = twoHandSwordSkill;
}
else if(col.GetComponent<Item>().currentWepType == "axe")
{
currentWeaponType = "1h axe";
skillType = "axeSkill";
skillDisplay = axeSkill;
}
else
{
currentWeaponType = "unarmed";
skillType = "unarmed";
}
}
Neither of those update until I take a step. If this is intended, is there any similar function I can use to OnTriggerStay that updates every frame like Update()?
I've noticed similar behaviors. For triggers and collision detection, these operations aren't triggered unless there has been a change in the position of one of the rigid bodies involved otherwise these rigid bodies will 'sleep'
Answer by supercouge · Jul 13, 2013 at 09:12 PM
I had a similar problem with OnTriggerStay().
Just to be sure, did you check with the Debug.Console, that OnTriggerStay wasn't called? If you have checked that OnTriggerStay wasn't called, then in your Update() function add this line:
void Update() {
transform.position = transform.position + Vector3.zero;
]
Back then, this had solved my problem. However, I'm not sure why this problem happens.
Weird, i just checked, and until I start moving, it doesn't update the triggerStay to include the newly changed tag.
Your solution worked, but I assume that would be really inefficient use of processing power.
Your answer