Thursday, 10 July 2014

Keep it local.

I'm preparing a future post which is growing by the minute. I'll probably have to break it down a bit to keep it clear. Here's a bit I'll refer to in the (near) future.

I mentioned the World Position minus Object World position to make things local before, but I didn't explain it properly. 

 The WorldPosition gives you the world position value per pixel, whereas the ObjectWorldPosition gives you the world position of your object, just the value at which its center is.
When you subtract the ObjectWorldPosition to the WorldPosition it means that every pixel will have a fixed value wherever you place it in the map. The value becomes relative to the center.
Imagine that this quad is in the world. We check the value of the same pixel at different arbitrary locations. WorldPosition - ObjectWorldPosition always returns the same value.
(Remember, if you're thinking of a formula don't just keep it abstract. Give it some numbers to verify that the result makes sense.)

This set up is useful if you want to be able to move your object around and you want the material to stick to it, it is also good for you to ‘tame your value.
Sometimes you can be testing a feature in your test map, but as you implement it in the game, some things will go crazy. Depending on where you are in a map, the output of the WorldPosition could range from 1 to tens of thousands. Would you be to use the WorldPosition as, say a multiplier, you can see where the troubles start.

We had that in DmC 5 with the summoner. She's a flying enemy so the character team put some vertex offset in her hair to give it a floating motion. To do so they used the world position to drive some sine waves. The first tests were looking good in the test map but her hair first went all over the place in gameplay. The fix was just a matter of subtracting the ObjectWorldPosition to the WorldPosition.

No comments:

Post a Comment