I've been using boolean values to switch integer and float values between positive and negative (as in, if the boolean is true, the integer value is positive, else it is negative) successfully, but i can't help but feel like the way I'm doing this is in an over complicated manner, as i tend to overlook simple solutions to simple problems. Perhaps there is a simpler way of doing this? Here are the two techniques i have found to work.
player_offset.x = abs(player_offset.x)*(int(LeftRight)*2-1)
This one changes the X component of a Vector2 value. It does this by converting the boolean "LeftRight" to an integer, which would be either 1 or 0, then multiplying the integer by 2 and subtracting 1, resulting in either 1 if the value is true, or -1 if it is false. The absolute value of the Vector2 X value is multiplied by this result.
Here is the other method:
player_offset.x = abs(player_offset.x) * [-1,1][int(LeftRight)]
This one works by using the boolean converted to an integer as an index for a list containing -1 and 1 to multiply the vector component. If the value is false, then the vector component is multiplied by -1, else it is multiplied by 1.
Both of these methods work, but I feel like they are unnecessarily complicated, and could perhaps lead to performance issues as they are called every frame.
Does anyone know a simpler way to do this?