{"id":977,"date":"2012-04-02T14:15:09","date_gmt":"2012-04-02T18:15:09","guid":{"rendered":"http:\/\/www.oztalay.com\/matt\/?p=977"},"modified":"2012-04-07T05:24:17","modified_gmt":"2012-04-07T09:24:17","slug":"player-position-based-material","status":"publish","type":"post","link":"http:\/\/www.oztalay.com\/matt\/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><!--more--><\/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.\u00a0(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<p>&nbsp;<\/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,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[205],"tags":[203,202,204,171],"class_list":["post-977","post","type-post","status-publish","format-standard","hentry","category-tech-art-2","tag-kismet","tag-material","tag-player-position","tag-udk"],"_links":{"self":[{"href":"http:\/\/www.oztalay.com\/matt\/wp-json\/wp\/v2\/posts\/977","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.oztalay.com\/matt\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.oztalay.com\/matt\/wp-json\/wp\/v2\/types\/post"}],"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=977"}],"version-history":[{"count":11,"href":"http:\/\/www.oztalay.com\/matt\/wp-json\/wp\/v2\/posts\/977\/revisions"}],"predecessor-version":[{"id":1151,"href":"http:\/\/www.oztalay.com\/matt\/wp-json\/wp\/v2\/posts\/977\/revisions\/1151"}],"wp:attachment":[{"href":"http:\/\/www.oztalay.com\/matt\/wp-json\/wp\/v2\/media?parent=977"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.oztalay.com\/matt\/wp-json\/wp\/v2\/categories?post=977"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.oztalay.com\/matt\/wp-json\/wp\/v2\/tags?post=977"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}