playMaker

Author Topic: Color Picker Confusion  (Read 1752 times)

acornbringer

  • Junior Playmaker
  • **
  • Posts: 75
    • Acornbringer.com
Color Picker Confusion
« on: March 26, 2018, 04:16:42 PM »
Hi there!

I'm trying to get a color picker to work so the player can adjust colors of game objects using a swatch of colors rather than inputting values or using preset colors.

After a bit of searching around, I came up with this setup of actions (image attached).

When I click in the scene on an object with my color palette texture applied, the only variables I'm able to get are the "V3_Ray_HitPoint" and the "V3_MousePosition". Everything else stays at default and I'm not sure why.

The "Get Pixel Color" action only accepts Int so I end up needing to convert the V2 XY from Float to Int but maybe that's causing trouble? It just feels a little hacky so maybe I'm using the wrong action altogether.

The other issue I'm having is the raycast is only projecting from the center of the camera instead of from where my mouse is even though I'm using just the "V3_MousePosition" as the start position. Because of this, I lined the textured object up with the camera to be sure the raycast was hitting but saw the same results.

Let me know if I should clarify anything! And any help is appreciated :)

Deek

  • Full Member
  • ***
  • Posts: 133
Re: Color Picker Confusion
« Reply #1 on: March 29, 2018, 08:42:28 PM »
I think the main problem is that you normalize the mouse position in 'Get Mouse Position', while setting the space in 'Raycast' to be local ("Self"). If you normalize any screen related measurement, you convert it from local space to view port space (wich is the current point on the screen in relation to the corners, a.k.a. bottom left is 0,0 | top left is 1,1 | middle of the screen is 0.5,0.5). So if you untick that, both actions should be in local space.
I've also read on a similar problem, that Unity flips textures on the y axis internally and I doubt that 'Get Pixel Color' has taken that into account, so you might need to invert the "Int_TextureCoord_Y" variable before 'Get Pixel Color' (by using 'Int Operator' and multiplying with -1).
Also you haven't set a GameObject in your 'Raycast' action. I assume you'd need to set the camera that can display the texture in there and make sure that it is in front of the texture, otherwise you'd have to flip the z-direction.

That 'Get Pixel Color' requires int variables is actually correct, because it uses the pixel of the texture to determine the current position, which are expressed in natural numbers.

In general I'd suggest that you enable Debug-mode (at the bottom of the 'State'-tab next to "Hide unused"), then you can see all the runtime values of set variables, which makes it easier to see on which action it starts to give an unexpected result.

I could also imagine that the 'Get Raycast Hit Info Extras' action is either not the right choice for this endeavor or doesn't work correctly.