collapse

Welcome to VRTITTIES

A place for VR Porn Games, Oculus Rift Porn Games, Vive Porn Games, VR Porn Game Downloads & VR Sex Games.

Please feel free to discuss anything about Oculus Rift Porn Games, Vive Porn Games and VR Porn Games.

The answer to the anti spam question is facebook. If you have any issues registering then flick me an email or post as a guest. If you make an account you do not have to answer any anti spam questions after 10 posts.

You will need to sign up to the forum and make a number of posts before you can post links to other websites.

If you are ever looking at buying some VR Porn please use my affiliate links on the right sidebar.

Thanks,

VRTITTIES, New Zealand

Chelsearift@gmail.com


Author Topic: Tutorial - Dynamic head tracking in UE4  (Read 14686 times)

Syncret

  • VR Porn Fiend
  • ***
  • Posts: 54
Tutorial - Dynamic head tracking in UE4
« on: November 30, 2014, 11:40:16 AM »
This quick tutorial will show you how to get a character in Unreal to look at the camera.
(This assumes you know the basics of getting an animation blueprint set up and running on your character.)

First, add a Look At node to your animation blueprint, and wire it in between your animation source and your final pose:


  • The Local to Component and Component to Local nodes will be created for you automatically.
  • Select your Look At node and click "(As pin) Look at Location" to expose the look at location. This will allow us to feed a look at location to the node from an external source.
  • The Alpha pin determines how strongly you want the look at to affect the character. 1 means the look at node has complete control of the bone, 0 means that the bone is under animation control and the look at node is ignored, and any value in between blends look at with animation input.
  • The Bone to Modify is the bone on the character's skeleton that you want to be controlled by this node. Usually this will be the Head.
  • The Look At Axis is the forward axis for this bone - it's the axis that should point at the Look at Location. You may have to experiment a bit to find out which axis is right for your particular skeleton. For MMD models coming in through Unity, the Z axis is forward.
In the next section, I'll show you how to generate some data to feed to this node.



Syncret

  • VR Porn Fiend
  • ***
  • Posts: 54
Re: Tutorial - Dynamic head tracking in UE4
« Reply #1 on: November 30, 2014, 12:09:22 PM »
The next thing we're going to do is create a pair of functions to feed information to the Look At node.
  • First, let's create a place to put them. In your content browser, if you haven't already created a "Blueprints" directory, make one now. We'll create a new directory inside Blueprints called "Libraries". The names aren't important - they're there purely for our own organization.
  • Now we'll create a blueprint library to store our functions. Blueprint libraries are a useful way to create functions that can be used in many places throughout your game. Right-click inside your Libraries directory, and select Blueprints->Blueprint Function Library. We'll name our new library "Animation Functions".
  • Open up your new blueprint library, and from the My Blueprint panel, hit the Function button to create a new function. We'll name it "GetPlayerCameraLocation"

  • Leave your function Public, but check the "Pure" checkbox. This indicates that your function only retrieves data, but doesn't modify any objects, and can therefore be called at any time without having to be added to the execution flow. (Don't worry if you're not sure what I'm talking about here. For programmers out there, marking a function as pure is similar to marking it const in C++.)
  • Because this function is sitting in a library and could be called from anywhere, we need to give it an object to reference so it can grab the World object. Create an "Object" input, and label it WorldContextObject.
  • Our output will be a vector. We can call that CameraLocation.
  • Finally, we need to create a local Vector variable we can use as a scratchpad within our function. We'll call this LocalCameraLocation.



Syncret

  • VR Porn Fiend
  • ***
  • Posts: 54
Re: Tutorial - Dynamic head tracking in UE4
« Reply #2 on: November 30, 2014, 12:17:56 PM »
  • Now it's time to wire up our Blueprint according to the pattern you see in the screenshot. I'll assume you've already done the basic Blueprint tutorials (if you haven't, you should), so I'll just describe what it's doing.
  • First, we're initializing our LocalCameraLocation variable to (0,0,0) so we have a value to return if we're not able to get our Camera Manager yet.
  • Next, we're grabbing our Player Camera Manager, and since this isn't a splitscreen game, we can safely assume our player is player 0.
  • This Camera Manager isn't guaranteed to exist throughout our game session, so we're using an IsValid macro to make sure we only try to read from it if it's there. The unused IsNotValid branch will just automatically go to the Return node, so if it fails, it'll just return the (0,0,0) vector we've already set in our local variable.
  • Now we're grabbing our Camera Manager's transform component (which describes the camera's location and rotation), and as long as it's valid, we're reading its Relative Location and writing that into our local variable, which we then return.
  • This will allow us to call this function from our animation blueprint and get the camera's current location.
Next, we'll wire the new function into our animation blueprint.

Syncret

  • VR Porn Fiend
  • ***
  • Posts: 54
Re: Tutorial - Dynamic head tracking in UE4
« Reply #3 on: November 30, 2014, 12:29:09 PM »
Now if you right-click in your animation blueprint, you'll see that the GetPlayerCameraLocation function you created in your library (assuming you've compiled and saved your library) is now usable.

  • Add it in and wire its output to your Look At node's Look At Location.
  • We also need to supply a world context object for our function. The animation blueprint's Pawn Owner is a safe bet - if the animation blueprint is running, we can be sure the pawn is there. Call TryGetPawnOwner and feed its return value into the World Context Object pin in your blueprint function.
  • For now, leave your Alpha set to 1, and try testing the model in-game. You should see the character trying to look at the player camera.
  • If the head is moving at crazy angles when it tries to look, there are two things you'll want to check: Is the Look At node affecting the right bone? (You'll get funky results if it's trying to aim the Neck, or some other bone, at the target.) Have you chosen the right forward axis for your bone?
Once you get this running, you'll probably notice that your character tries to look at the camera even when it's behind her head, causing some fairly unpredictable results. In the next section, we'll create a method to decide when the character should look, and when she shouldn't.

Syncret

  • VR Porn Fiend
  • ***
  • Posts: 54
Re: Tutorial - Dynamic head tracking in UE4
« Reply #4 on: November 30, 2014, 12:50:59 PM »
For this bit, we're going to head back to the library we created earlier, and add a new function called GetLookAtAlpha.

  • Leave it Public, and mark it Pure.
  • Now we need to tell it who's doing the looking and where they're looking. Create a "Pawn" input, and name it PawnOwner.
  • Create a "Vector" input, and name it LookLocation.
  • Create a "Float" output, which we can call LookIKAlpha.
  • Wire up the blueprint as shown. The node coming from the two normalized vectors is a "Dot Product" node.
Here's what it's doing:
  • First, we're grabbing the supplied pawn's rotation and getting its Forward vector and normalizing it. (Normalizing a vector turns it into a "Unit Vector" - a vector with a length of exactly 1.)
  • Next, we're taking the supplied Look Location vector, and subtracting our supplied Pawn's location vector from it. This gives us a vector pointing from the pawn to the target location. We need to normalize this too.
  • Now, we take the Dot Product of these two vectors, which give us the cosine of the angle between them. This will be a value from -1 to 1. The closer the two vectors are to being perfectly aligned, the closer to 1 this value will be. If they're pointing opposite each other, this value will approach -1. It'll be 0 if they're perpendicular.
  • Finally, since we're only interested in locations in front of our pawn, we can use a Max function to clamp negative values to 0.
  • This is a really basic function that will return a value of 1 whenever the camera is directly in front of the pawn, and scale it down to 0 when the camera gets near the side of the character or behind her.
Note that there are a ton of ways we could improve this function, but I've opted to leave this function fairly simple for now.



Syncret

  • VR Porn Fiend
  • ***
  • Posts: 54
Re: Tutorial - Dynamic head tracking in UE4
« Reply #5 on: November 30, 2014, 01:00:00 PM »
Finally, let's wire this new function into our LookAt node's Alpha pin:

  • Feed the Pawn Owner we were using as our World Context Object into the Pawn Owner pin.
  • Feed the result of our Get Player Camera Location function into the Look Location pin.
When you run it, your character should only try to look at the camera when it's reasonably in front of her.
Note - if instead she's doing the look when the camera's out to one side or the other, check to make sure her Character setup has the mesh properly facing along the forward vector. MMD models, by default, will be pointing to the right of forward.

That's it! There are a ton of ways we can improve our Look IK - we could create a much more elaborate function to choose the location she looks at, so she looks at other characters when they're nearby, and at the camera otherwise... We could do a lot more with the LookAt alpha function to get her looking at the camera through a wider range of angles, and to ignore it beyond a certain distance... Lots we could do, but this is enough to get things started. Good head tracking can add a lot of presence to characters. Have fun!

Will

  • Administrator
  • VR Porn Addict
  • *****
  • Posts: 318
    • Patreon VRTitties
Re: Tutorial - Dynamic head tracking in UE4
« Reply #6 on: January 07, 2015, 11:31:52 AM »
Awesome tutorial thanks Syncret!

How do you get the head to follow the rift's positional tracking?

Also I'm having a bit of trouble with
Quote
Because this function is sitting in a library and could be called from anywhere, we need to give it an object to reference so it can grab the World object. Create an "Object" input, and label it WorldContextObject.

Whenever I connect that the game crashes but it works without it.

Update: I tried using the Get Orientation and Position of HMD but encountered this bug https://forums.unrealengine.com/showthread.php?32060-Device-Position-Bug
« Last Edit: January 09, 2015, 12:26:59 AM by chelsearift »

Syncret

  • VR Porn Fiend
  • ***
  • Posts: 54
Re: Tutorial - Dynamic head tracking in UE4
« Reply #7 on: January 10, 2015, 05:54:35 AM »
I'm getting the positional tracking information using the HMD library's GetOrientationAndPosition() method, and using it to transform the player camera's location and rotation. GetOrientationAndPosition() gives you a relative offset from the camera position.



Not sure what's going on with the world context object in your library method. Hmm.

Will

  • Administrator
  • VR Porn Addict
  • *****
  • Posts: 318
    • Patreon VRTitties
Re: Tutorial - Dynamic head tracking in UE4
« Reply #8 on: January 10, 2015, 10:37:01 AM »
Ah that works :)

Thanks so much for that I would never have figured that out myself and there is nothing on the net to help atm.


rift1

  • Guest
Re: Tutorial - Dynamic head tracking in UE4
« Reply #9 on: January 11, 2015, 05:48:41 AM »
Syncret, is it my imagination or did you get the eyes working as well in private dance?

I found this post on the ue4 forums that looks useful but im still learning and haven't managed to get it working yet.  I've also had trouble following your guide here as all that happens is the head looks at the floor.  :-[

http://forums.unrealengine.com/showthread.php?50285-Eye-contact

Syncret

  • VR Porn Fiend
  • ***
  • Posts: 54
Re: Tutorial - Dynamic head tracking in UE4
« Reply #10 on: January 11, 2015, 07:13:14 AM »
I did. Actually for the eyes, I just added additional LookAt nodes to the anim blueprint, and fed them the same data I'm feeding the head. You can get some decent results by playing with the tolerances a bit so she'll look with her eyes before her head.

Yeah, the stuff on the thread there is more complicated than it needs to be, I think. I find the best way to go is to build piece by piece and test each bit as you go.

re: looking at the floor:
If she's looking at the floor consistently, without changing orientation to your movement, that means your camera location data is probably coming in empty, so she's looking at the world origin (0,0,0). If she's moving her head, but looking 90 or 180 degrees off where she should be, that means the axis is set incorrectly on your LookAt node.

rift1

  • Guest
Re: Tutorial - Dynamic head tracking in UE4
« Reply #11 on: January 11, 2015, 07:56:54 AM »
Cool would be nice to see a screenshot of the eye setup if possible. im new to blueprints but luckily i did manage to get head look working now.

Turns out it was the WorldContextObject that wasn't working like mentioned above, so i deleted that and it seems to work ok except when it comes to the alpha side of things, the head still rotates behind.  HMD position also works as well once i added that. Thanks!

reply

  • Guest
Re: Tutorial - Dynamic head tracking in UE4
« Reply #12 on: February 04, 2015, 12:46:10 AM »
I love how creepy 20 models with no alpha setting following your gaze are. The fact that the models are naked does not help either.. stuff like this probably spawned the idea for silent hill 4.

Anyways, great tutorial, but for some reason, the trygetvalue for the player pawn did not work for me, but just get player pawn works. Does the game crash if no player is present? I would assume the engine still is able to catch that exception and just uses some empty variable.

 

* Download VRtitties

* VRtitties Affiliate Links

* Forum Staff

Will admin Will
Administrator