Player Position-based Material

Recently, a coworker posed a question to me:
“How do you pass the player position to a material in UDK?”

“Well, couldn’t you just use the CameraWorldPosition node? The player and the camera are so close together the effect should be enough, right?” replied I.

“That could work, but I want to do a far-back third-person camera,” he countered.

“Oh…” I said.

After attempting a solution that was, admittedly, rather hacky involving trying to programmatically derive the location of the player based off a known distance between the camera and the player, I opted for something that could be considered hacky, but is as close to a programatic solution as an artist can get.

Looking into the situation, I thought perhaps I could use Kismet to pass the position of the player to a Material Instance using the Set VectorParam node… only to find out that node was taken offline back in 2010. Of course, with the clever use of “Append Vector” nodes, three scalar parameters can quickly turn into a float3, right?

 

Do excuse the garish colors. They were chosen to best showcase what’s happening. This could certainly be used to implement more subtle effects.

 

So that’s what I did. Here’s the base material (click to enlarge)

And the kismet setup. I put a delay after the operation is complete, otherwise Kismet throws a “too many operations” error. The delay is .033 seconds, or roughly 1 frame at 30 frames per second. The delay is barely perceptible, and it minimizes the number of calculations that have to happen. (click to enlarge)

Combining all that, you get this (video forthcoming):

From a CameraActor:

3 replies on “Player Position-based Material”

Hey, Cheers for the script, it works pretty neatly.
I am trying to use it with particles and have run into an issue where it does not change the texture based on location and distance when I jump. Is this something that could add to all 3 axis like a metaphorical sphere around the player?

Cheers again
-Rick

Hey Rick,

I think that’s happening here is that it’s getting the location of the player’s root bone which, if I recall correctly, stays on the ground when the pawn plays its jumping animation. It’s not something I’d ever thought about, actually. If you want to try to test this hypothesis, fall off a tall spot and see what happens, or fly around in ghost mode and see how it reacts.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.