{"id":992,"date":"2012-04-02T14:50:04","date_gmt":"2012-04-02T18:50:04","guid":{"rendered":"http:\/\/www.oztalay.com\/matt\/?page_id=992"},"modified":"2012-04-02T14:51:05","modified_gmt":"2012-04-02T18:51:05","slug":"player-position-based-material","status":"publish","type":"page","link":"http:\/\/www.oztalay.com\/matt\/tutorials\/player-position-based-material\/","title":{"rendered":"Player Position-based Material"},"content":{"rendered":"<p>Recently, a coworker posed a question to me:<br \/>\n&#8220;How do you pass the player position to a material in UDK?&#8221;<\/p>\n<p>&#8220;Well, couldn&#8217;t you just use the CameraWorldPosition node? The player and the camera are so close together the effect should be enough, right?&#8221; replied I.<\/p>\n<p>&#8220;That could work, but I want to do a far-back third-person camera,&#8221; he countered.<\/p>\n<p>&#8220;Oh&#8230;&#8221; I said.<\/p>\n<p>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.<\/p>\n<p>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&#8230; only to find out that node was taken offline back in 2010. Of course, with the clever use of &#8220;Append Vector&#8221; nodes, three scalar parameters can quickly turn into a float3, right?<\/p>\n<p>&nbsp;<\/p>\n<p>Do excuse the garish colors. They were chosen to best showcase what&#8217;s happening. This could certainly be used to implement more subtle effects.<\/p>\n<p>&nbsp;<\/p>\n<p>So that&#8217;s what I did. Here&#8217;s the base material (click to enlarge)<\/p>\n<p><a href=\"http:\/\/www.oztalay.com\/matt\/wp-content\/uploads\/playerPos_material.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-large wp-image-980 alignnone\" title=\"playerPos_material\" src=\"http:\/\/www.oztalay.com\/matt\/wp-content\/uploads\/playerPos_material-1024x580.jpg\" alt=\"\" width=\"640\" height=\"362\" srcset=\"https:\/\/www.oztalay.com\/matt\/wp-content\/uploads\/playerPos_material-1024x580.jpg 1024w, https:\/\/www.oztalay.com\/matt\/wp-content\/uploads\/playerPos_material-300x170.jpg 300w, https:\/\/www.oztalay.com\/matt\/wp-content\/uploads\/playerPos_material.jpg 1920w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/a><\/p>\n<p>And the kismet setup. I put a delay after the operation is complete, otherwise Kismet throws a &#8220;too many operations&#8221; 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)<\/p>\n<p><a href=\"http:\/\/www.oztalay.com\/matt\/wp-content\/uploads\/playerPos_kismet.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-large wp-image-979 alignnone\" title=\"playerPos_kismet\" src=\"http:\/\/www.oztalay.com\/matt\/wp-content\/uploads\/playerPos_kismet-1024x410.jpg\" alt=\"\" width=\"640\" height=\"256\" srcset=\"https:\/\/www.oztalay.com\/matt\/wp-content\/uploads\/playerPos_kismet-1024x410.jpg 1024w, https:\/\/www.oztalay.com\/matt\/wp-content\/uploads\/playerPos_kismet-300x120.jpg 300w, https:\/\/www.oztalay.com\/matt\/wp-content\/uploads\/playerPos_kismet.jpg 1406w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/a><\/p>\n<p>Combining all that, you get this (video forthcoming):<\/p>\n<p><a href=\"http:\/\/www.oztalay.com\/matt\/wp-content\/uploads\/playerPos_playerView.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-985\" title=\"playerPos_playerView\" src=\"http:\/\/www.oztalay.com\/matt\/wp-content\/uploads\/playerPos_playerView-1024x574.jpg\" alt=\"\" width=\"640\" height=\"358\" srcset=\"https:\/\/www.oztalay.com\/matt\/wp-content\/uploads\/playerPos_playerView-1024x574.jpg 1024w, https:\/\/www.oztalay.com\/matt\/wp-content\/uploads\/playerPos_playerView-300x168.jpg 300w, https:\/\/www.oztalay.com\/matt\/wp-content\/uploads\/playerPos_playerView.jpg 1277w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/a><\/p>\n<p>From a CameraActor:<\/p>\n<p><a href=\"http:\/\/www.oztalay.com\/matt\/wp-content\/uploads\/playerPos_cameraView.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-986\" title=\"playerPos_cameraView\" src=\"http:\/\/www.oztalay.com\/matt\/wp-content\/uploads\/playerPos_cameraView-1024x574.jpg\" alt=\"\" width=\"640\" height=\"358\" srcset=\"https:\/\/www.oztalay.com\/matt\/wp-content\/uploads\/playerPos_cameraView-1024x574.jpg 1024w, https:\/\/www.oztalay.com\/matt\/wp-content\/uploads\/playerPos_cameraView-300x168.jpg 300w, https:\/\/www.oztalay.com\/matt\/wp-content\/uploads\/playerPos_cameraView.jpg 1277w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Recently, a coworker posed a question to me: &#8220;How do you pass the player position to a material in UDK?&#8221; &#8220;Well, couldn&#8217;t you just use the CameraWorldPosition node? The player and the camera are so close together the effect should be enough, right?&#8221; replied I. &#8220;That could work, but I want to do a far-back [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":407,"menu_order":0,"comment_status":"open","ping_status":"open","template":"","meta":{"footnotes":""},"class_list":["post-992","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"http:\/\/www.oztalay.com\/matt\/wp-json\/wp\/v2\/pages\/992","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.oztalay.com\/matt\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"http:\/\/www.oztalay.com\/matt\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"http:\/\/www.oztalay.com\/matt\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.oztalay.com\/matt\/wp-json\/wp\/v2\/comments?post=992"}],"version-history":[{"count":3,"href":"http:\/\/www.oztalay.com\/matt\/wp-json\/wp\/v2\/pages\/992\/revisions"}],"predecessor-version":[{"id":995,"href":"http:\/\/www.oztalay.com\/matt\/wp-json\/wp\/v2\/pages\/992\/revisions\/995"}],"up":[{"embeddable":true,"href":"http:\/\/www.oztalay.com\/matt\/wp-json\/wp\/v2\/pages\/407"}],"wp:attachment":[{"href":"http:\/\/www.oztalay.com\/matt\/wp-json\/wp\/v2\/media?parent=992"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}