WorldPositionOffset was discussed in a couple of cases earlier in this chapter, and there's one more interesting case: how Interactive Foliage Actors use this feature. An Interactive Foliage Actor needn't have anything to do with foliage, but that is what it is often used for. Epic Games provides a video of the actor being used to create a field of undergrowth which reacts to the bounds of a Bot as it runs around amongst it: http://udn.epicgames.com/Three/rsrc/Three/InteractiveFoliageActor/WalkingThroughFields.mp4. A spring system automatically applied to the actor (it can be any StaticMesh) drives the interaction.
In this recipe we'll look at what we can do with the Material nodes that are involved, using the node which possibly has the longest name of all: FoliageNormalizedRotationAxisAndAngle.
float angle = b; float cosAngle = cos(angle); float sinAngle = sin(angle); float3 A = float3((a.x*cosAngle - a.y*sinAngle), (a.y*cosAngle + a.x*sinAngle),a.z-20); return A;
-20
after the z
in the expression, you will get rotation around a different axis. As it is, the impulse applied to the PowerCore actor will turn it to spin around its vertical axis, a bit like a Tibetan prayer wheel.1
. Add another, and name it 2
.This example's functionality comes from the mathematics that output a float angle depending on the direction from which the player hits the actor in the scene. This is fed in to the RotationAboutAxis node , and the Constant in the expression defines the intensity of the spring. You could also effect the spring setting by opening the InteractiveFoliageActor properties and expanding the Foliage Physics section to expose the values for its Impulse Scaling, Stiffness, and Dampening.
In the previous example, we set the code segment in the custom node FloatAngle:
... float3 A = float3((a.x*cosAngle - a.y*sinAngle), (a.y*cosAngle + a.x*sinAngle),a.z-20); return A;
If you set it as follows, which is only a small change, you can change the nature of the bobbing of the object:
... float3 A = float3((a.x*cosAngle - a.y*sinAngle), (a.y*cosAngle + a.x*sinAngle),a.z); return A;
You then will probably want to adjust the nodes as seen in the next screenshot (in particular by Subtracting 25 from the ObjectWorldPosition so as to lower the PositionOnAxis):
By default, it bobs around its center, which only looks okay when it is spinning around its up axis. If you want a sideways rocking motion, dropping the PositionOnAxis works because we set the Collision Height for the PowerCore to be 60, so the subtraction of 25 puts it at the base (or just above). The Constant driving the spring intensity should be reduced as the rocking motion looks more extreme than the spinning motion. A demo is provided: Packt_09_IFA_DEMO.UDK. Two of the PowerCore actors are set to rock and another two are set to spin.
3.129.63.114