#Debugging Trigger Not Being COnsistant

1 messages Β· Page 1 of 1 (latest)

fathom glade
#

Here @zenith trellis im going to make a thread if are you willing to help me debug this

#

Thank you!

zenith trellis
#

So first question: what's the pattern to when it fires vs when it doesn't?

fathom glade
#

Also @cyan tinsel is another developer on this project so hes just watching in case he has any ideas lol

zenith trellis
#

or, well, actually, question #0: how do you know it's not firing consistently?

cyan tinsel
#

Hello

fathom glade
#

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

zenith trellis
#

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

fathom glade
#

using a raycast?

#

or something else

zenith trellis
#

using math

fathom glade
#

you able to show an example of something i might use

zenith trellis
#

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

fathom glade
#

okay i think im following

#

this math is a little over my head πŸ˜† but i think ill understand as we keep talking lol

zenith trellis
#

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

fathom glade
#

i think this makes sense im just still a little confused. this is like the most complicated thing ive tried to code yet haha

zenith trellis
#

like, suppose you have this, and you are trying to compute 'is the red dot inside the flashlight cone or not'

fathom glade
#

i think i understand the math i just don't know how i would code that

zenith trellis
#

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

fathom glade
#

okay that makes sense

#

is the player the flashlight

#

the red dot is the object we are shining at

zenith trellis
#

yes

fathom glade
#

okay

zenith trellis
#

I mean, the player is the crappy stick-figure I drew on the left, but yes

fathom glade
#

okay i understand

zenith trellis
#

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

fathom glade
#

okay

zenith trellis
#

so in practice you need to be able to do three things:

  1. Get the vectors that represent the red and grey lines
  2. Measure the angle between them
  3. Compare it to 'x'
fathom glade
#

and does it work in all three axis?

#

cuase our project is 3D

zenith trellis
#

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

fathom glade
#

ahhhhh

#

i seee

#

how would I code this LMAO

#

never done anything like this

zenith trellis
#

so, work through the three steps πŸ™‚

fathom glade
#

I get the concept now though so thank you

zenith trellis
#

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

fathom glade
#

alright

zenith trellis
#

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

fathom glade
#

okay

#

then what do you compare VectorToObject and what?

zenith trellis
#

and for step 3 - well I hope you already know how to compare two numbers πŸ™‚

fathom glade
#

haha

#

my brain is a little fried πŸ˜†

zenith trellis
#

you feed vectorToObject and flashlightForwardDirection into Vector3.Angle

#

and it will give you back angleBetweenFlashlightAndObject

fathom glade
#

OHHH

#

and then all this stuff would happen in update()?

zenith trellis
#

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

fathom glade
#

OH OKAY

#

I SEE

#

god damn this is the most complicated thing ive ever had to do so far lol

zenith trellis
#

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?"

fathom glade
#

ah i see

zenith trellis
#

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

fathom glade
#

yes you are rigfht to assume that

#

my little highschool senior brain is starting to understand

zenith trellis
#

hehe

fathom glade
#

thank you!

#

Seriously thank you so much

zenith trellis
#

you're welcome. Use what I have explained to go make something cool 😎

fathom glade
#

i will try!

#

im going to try to implent that and Ill shoot you a message if i need any assistance

zenith trellis
#

sure thing πŸ™‚

fathom glade
#

god tier mathmatecian uber over here

zenith trellis
#

haha. Mm, once you get the hang of this kind of technique you will find that it crops up EVERYWHERE πŸ˜‰

fathom glade
#

@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