Playmaker Forum
PlayMaker Help & Tips => PlayMaker Help => Topic started by: frogwise on May 03, 2015, 11:30:22 PM
-
Hey everyone,
I have a stationary object, and a moving player. I am checking the distance between player and object every frame. The object is black.
What I would like to do is have the object change to white based on how close the player gets to it. So, for example, the minimum distance for the object to start transitioning from black to white is 20, and a distance of 3 sets the color to 100% white. Once the distance is that close, the object stays white forever.
Any elegant solutions for this? Thanks so much in advance. :)
-
Hi Frogwise!
I don't think there is an "elegant"(aka simple) way to do that, but it's not that complicated tho.
Simply try to use a "get distance" action in the GameObject subsection. Then store the float value (don't forget to check "every frame") and use a "float compare" action to send an event to an other state when your float value is under a certain value.
Then in this new event, do an action to set a new texture as you want.
Hope this will help :-)
-
Thanks for the reply.
I'm actually more confused about how to smoothly fade between two colors based on that distance.
For example, at a distance of 5 it starts to fade to the new value based on how close you get. If, for example, you get further away again, it starts to fade back to the original color.
I could do this with a Color Ramp, but the color ramp will only work between 0-1 values, or 1 and 2. I don't know how to map my distance values in a normalized way like this.
-
There's a "Remap float " action that Jean made that could help you with this http://hutonggames.com/playmakerforum/index.php?topic=5122.msg24311#msg24311 (http://hutonggames.com/playmakerforum/index.php?topic=5122.msg24311#msg24311)
-
The Remap-thing sounds good.
But remember that 0-1 values are basically percentages divided with 100.
If you have your two outer distance values (5 and 0 -- and 5 being 100%) you could find the percentage based on the current distance -- every frame, and set the color value based on that.
/Bad
-
Thanks for opening up my eyes to the power of division! It's working now, however, I am noticing that the transition of the colors is very fast. They do "fade" into each other, but very quickly. Is there a way I could curve the float to be less sensitive to transition at the maxDistance, and faster at the minDistance? Here is my setup that works currently.
-
I guess the problem I am having is that for some reason, a now-normalized distance value of 0.5 is not producing a good halfway point blend between my two colors. For some reason, by a distance of 0.9, I am already pretty much at my target color. This is why I am seeing such a quick transition.
-
Fixed it! The problem was that the color variable "color_current" was being used incorrectly. I was using it to grab the initial materials color, and then in the Color Ramp using the same variable to store the ramping color. I made a third color variable and used that. Works like a charm.
-
Whoups, just sent you a reply on your PM, didn't see your progress here.
Looks like you solved your riddles.
Good work.
/Bad