- Home /
Are Triggers not based upon normals?
Hi,
Here's the thing : Imagine a corridor. I want to change the color of each corridor's section I'm walking by to red if I'm walking in one way, but to blue if I'm walking the other way.
I thought to have two simple quads at eache edge of a section, with normals pointing towards each ways so if you walk through a trigger with normal not facing you it won't react. But it seems a 'is trigger' collision mesh doesn't work based upon normals as a mesh collider do. From whatever side I walk through the trigger, it is trigged.
Do you confirm that? Any alternative?
Answer by MrSkiz · Jul 23, 2012 at 03:06 PM
Ok, I solved the problem, thanks to Fattie's "gate" tips, by playing with two triggers sending custom strings into an array in another global trigger covering the section. I then concatenate (array.join) and, depending the result, I change the corridor section's color.
The A gate triggers (B is the same with "As" changed to "Bs":
function OnTriggerEnter (collisionInfo : Collider) {
if(collisionInfo.gameObject.tag=="BlueTeam") {
SendMessageUpwards ("PushSectionArray","BlueA");
}
else if(collisionInfo.gameObject.tag=="RedTeam") {
SendMessageUpwards ("PushSectionArray","RedA");
}
}
The global section trigger :
var sectionArray = new Array();
function OnTriggerStay () { if (sectionArray.length == 2){ var resultArrayJoin = sectionArray.join("-"); print (resultArrayJoin); if (resultArrayJoin == "BlueA-BlueB"){ SendMessageUpwards ("BlueClaim"); sectionArray.clear(); } else if (resultArrayJoin == "RedB-RedA"){ SendMessageUpwards ("RedClaim"); sectionArray.clear(); } else { sectionArray.clear(); } } }
function OnTriggerExit () { sectionArray.Clear(); }
function PushSectionArray (triggerEcho : String) { sectionArray.push(triggerEcho); }
The Red/blue changer code :
var colorActual : Color; var colorBlue : Color = Color.blue; var colorRed : Color = Color.red; var duration : float = 10.0;
function Start () { renderer.material.color = Color.grey; }
function BlueClaim () { colorActual = renderer.material.GetColor("_Color"); //var lerp : float = duration * Time.DeltaTime; var lerp : float = Time.time / duration; renderer.material.color = Color.Lerp (colorActual, colorBlue, lerp); }
function RedClaim () { var lerp : float = Time.time / duration; renderer.material.color = Color.Lerp (colorActual, colorRed, lerp); }
I just now have to figure how to make my Color.Lerp do a smooth transition. The same code of my Red/BlueClaim functions inserted in an Update() works as intended.
Answer by Meltdown · Jul 17, 2012 at 10:28 AM
Colliders are based on normals, yes, triggers are not.
Answer by MrSkiz · Jul 17, 2012 at 10:40 AM
I think I solved the case : I was assigning a mesh collider as trigger to an empty. So I was only colliding with the trigger.
But by using the quad mesh with transparent texture with it's mesh collider flagged as trigger it works as intended, the trigger responds only when I go through the mesh from the side where its normal is.
Any warnings regarding the use of this trick (if it's one...)?
edit : apparently it doesn't work.
Transparent texture? You can (or should) just remove the renderer of the plane... All you have left is the $$anonymous$$eshCollider with the plane mesh assigned.
How does your mesh look like? is it really plane? There could be tilted triangles. A screenshot of the mesh would help i guess.
Yes, it's just a cube from which I removed 5 of the 6 faces. And yes, unticking the renderer part make the object trigger only.
But with further experiments my trick doesn't work. I think I'll have to play with 2 triggers and check in which order they're triggered to find in which way the player is moving.
Your answer
Follow this Question
Related Questions
Can't click gameobject when over another trigger? 1 Answer
Normal map appears to be wrong when generated 2 Answers
audio trigger keydown 1 Answer
Get Player to 'Stick' to Surface 0 Answers
Trigger Respawn 3 Answers