#Debugging Trigger Not Being COnsistant
1 messages Β· Page 1 of 1 (latest)
So first question: what's the pattern to when it fires vs when it doesn't?
Also @cyan tinsel is another developer on this project so hes just watching in case he has any ideas lol
or, well, actually, question #0: how do you know it's not firing consistently?
Hello
i havent noticed a pattern. sometimes it will trigger immediatley sometimes it wont until the third or fourth time i do it. sometimes it never triggers
bassically we have game objects that spawn at windows in a house. you as the player (vr) shine a flashlight at the gameobject in the window
the flashlight has that cone shaped object with the mesh renderer disabled
the other thing that could be glitching is the animator but we just haven't been able to see anything that could be causing such a delay
oh, in this case I would probably not bother using colliders at all, I would just measure the distance and angle between the player and each of the objects
using math
you able to show an example of something i might use
your cone can be defined in terms of an axis (which runs from the tip of the cone down the middle of it) and an angle (between the axis and the 'edge'), right?
the larger the angle, the 'wider' the cone
okay i think im following
this math is a little over my head π but i think ill understand as we keep talking lol
the tip of the cone is where the player is, and the axis their look direction, and then the angle is some value you pick as a threshold, like maybe it's 20 degrees or something
so if what you are trying to figure out is "is a given point inside the cone or not" (where the given point is e.g. the pivot point of the object)
then what you can do is to take the vector from the player to the point, and measure the angle between that vector and the player's forward vector, and if it is less than the cone threshold then the point is inside the cone, otherwise it is not
it might be easier to imagine if you think about it in 2D, viewed from above
i think this makes sense im just still a little confused. this is like the most complicated thing ive tried to code yet haha
like, suppose you have this, and you are trying to compute 'is the red dot inside the flashlight cone or not'
i think i understand the math i just don't know how i would code that
well let me give a couple more diagrams and it should help clarify I think
so I was saying you can think of the flashlight itself as being an axis and an angle. so like this:
the grey line is down the center of the flashlight and the angle 'x' is from the center to the edge
okay that makes sense
is the player the flashlight
the red dot is the object we are shining at
yes
okay
I mean, the player is the crappy stick-figure I drew on the left, but yes
okay i understand
haha
so when we are interested in the red dot, we measure the angle between it and the grey line:
if y < x then it is inside the cone, but if y > x then it is outside the cone
okay
so in practice you need to be able to do three things:
- Get the vectors that represent the red and grey lines
- Measure the angle between them
- Compare it to 'x'
is this side view or birds eye view
and does it work in all three axis?
cuase our project is 3D
it actually doesn't matter whether it's side view or birds eye view, it works exactly the same both ways because your cone is inherently circular
so, work through the three steps π
I get the concept now though so thank you
step 1, for the vectors
you already know the grey line: it's just the direction the flashlight is pointed in (so I guess camera.transform.forward maybe?)
or flashlight.transform.forward or whatever
alright
for the red line, you get the vector between two positions by subtracting them. so like vectorToObject = object.transform.position - flashlight.transform.position
so that's your two vectors
for step 2: you can use https://docs.unity3d.com/ScriptReference/Vector3.Angle.html
and for step 3 - well I hope you already know how to compare two numbers π
you feed vectorToObject and flashlightForwardDirection into Vector3.Angle
and it will give you back angleBetweenFlashlightAndObject
it would happen whenever you want to check if the object is in the flashlight's cone or not, but sure, Update could be where you do that
OH OKAY
I SEE
god damn this is the most complicated thing ive ever had to do so far lol
now bear in mind - this technique does not care at all about "are there any obstacles in the way or not"
it JUST tests whether the object is in a position where it's within the cone of the flashlight
however
once you know that the object IS inside the cone
THEN you could do a Raycast to check "ok but is there anything blocking it from sight?"
ah i see
doing the calculations with the vector/angle is WAY cheaper than the Raycast so it's nice and efficient - you rule out most objects with the maths check, and then do the more expensive raycast only for the objects that are viable candidates
you might also want to check Vector3.Length(vectorToObject) to ignore objects that are further than a certain distance away from the player, assuming that your flashlight doesn't have infinite range
yes you are rigfht to assume that
my little highschool senior brain is starting to understand
hehe
you're welcome. Use what I have explained to go make something cool π
i will try!
im going to try to implent that and Ill shoot you a message if i need any assistance
sure thing π
god tier mathmatecian uber over here
haha. Mm, once you get the hang of this kind of technique you will find that it crops up EVERYWHERE π
@zenith trellis im gonna try to implement this tommorow when i have a fresher brain lol but you might be able to spot something if you take a look at this. Currently the ontriggerenter is just inconsistant and i dont know why
this is just a bit of a snapshot of all of this. let me know if you notice anything or have ideas
see how its inconsistant
sometimes it works sometimes it doesnt
for some reason it made the video a download
here is the link