How to make a bool change only when two other bools are both true or both false?

I want to check if an actor is fully on screen by checking if a point on top of the head and at its feet are on screen.

This works for one point:

However, this doesn’t work for both points, as it returns true if both are true, but false if only one is false:

How to make it change bool value only when both values change?

I’m slightly confused, because your goal is to determine if the character is on-screen.

The way that the character is determined to be on-screen is if BOTH values (top and bottom) are TRUE.

Therefore, if any one of them is FALSE, then then the entire function should be FALSE.

So… what is it that you want? For the function to only return FALSE if BOTH are FALSE? (Only after both are TRUE?)

I just need to be clear on that.

EDIT: If so-

2 Likes

If you want something to CHANGE then you need STATE.
So, you need to store a CalculatedVisibility boolean in the object.
Then, you need to update that CalculatedVisibility if both of the other booleans change.

The easiest way to do this is to create an UpdateCalcuatedVisiblity function.
Inside this function, check whether each value is different from the CalculatedVisibility.
If both values are different from the CalculatedVisibility then you flip the value of CalculatedVisibility. You can do this with two Branch nodes an a Set node that reads the value and passes it through NOT

When you then need to actually use this value, simply read the CalculatedVisibility boolean.

That being said – it seems unlikely that the behavior you say you want, is actually what you want. Try it, and if it doesn’t do what you expect it to, then maybe step back and describe in a little more details what rules you actually want to enforce.

(For example, what do you want if the “center of the mesh” is below the screen, but the “center of the head” is above the screen? Neither will be “on screen” but a bunch of … stuff … would be “on screen” if rendered.)

2 Likes

I want to know when the character enters or leaves the screen completely

I was kinda expecting something way simpler, like a logic gate i didn’t know of, or something.

here’s what I did:

1 Like

You may be complicating this.

I’m reading:

  1. If “Top_Of_Character” on-screen value EQUALS “Bottom_of_Character” on-screen value, proceed to next evaluation, else, test again.

  2. If “Been_Fully_on_Screen” value does NOT EQUAL “Top_of_Character” on-screen value, SET “Been_Fully_on_Screen” to unknown value (TRUE?) THEN set “Fully_On_Screen” to TRUE, else, test again from start.

EDIT: My question is where do you reset the “Fully_on_Screen” and “Been_Fully_on_Screen” values?

1 Like

It sounds like a de-spawning logic would be apropriate and much more optimized.

1 Like

Ah, I agree!

Default value for “onscreen” = false.

1 - If top of char and bottom of char are equal (so both on screen, or both not on screen) do 2, else out whatever “onscreen” was already set to.
2 - if top of char is different from whatever “onscreen” was already set to, then set value of “onscreen” to the same as itself, else out whatever “onscreen” was already set to.

how is this complicated? :sweat_smile:

I mean it already works. I was just wondering if it could be even simpler, like without those branches.

I don’t need to reset the value, just update whenever it changes

What’s that?

Then I misunderstood you. I thought you meant it DOES NOT work.

The logic gate you were looking for is XOR. It returns false if both are true or both are false.

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.