How to instantly set where the player is looking?

I'm not looking for aiming assist, just instantly setting where the first person player is looking.

This is for the start of my game. After the world is procedurally generated, I place the player near a flower (done) and then set the player to be looking directly at the flower. My previous first person library (First Person Exploration Kit) had this method, which I'm looking for the Opsive equivalent to:

playerController.forcePlayerLookToPosition(lookTarget); // lookTarget is a Vector3

Thank you
 
I needed something similar during cutscenes. (As well as being able to move the character)
The only way I was able to accomplish this myself was to detach the Camera Controller ILookSource from the player and then execute a look at target.

When my cutscenes start I call
C#:
EventHandler.ExecuteEvent<ILookSource>(m_OriginalCameraCharacter, "OnCharacterAttachLookSource", null);

Once I was done I then reattach the ILookSource (CameraController) to the player.
C#:
EventHandler.ExecuteEvent<ILookSource>(m_OriginalCameraCharacter, "OnCharacterAttachLookSource", m_CameraController);

I'm not sure if this is the correct way to handle this but it has worked for me.
 
You can use UltimateCharacterLocomotion.SetRotation to forcefully change the character's rotation. So you'd work out what the rotation that you need to set is (e.g. using Transform.LookAt), then apply this to the UCL component via that method.
 
This is why I had to disconnect the look ILookSource. What I found was that the character would rotate but the head would remain looking at the direction the camera was facing.

I will also note that it may be a bit different for me because I am using the FinalIK integration.
 
Sorry, seems I misunderstood the question a bit.

For this you'd want to look at creating a simple first person custom ViewType that uses Rotate to point the camera towards a specific transform/position, similar to the built-in Third Person LookAt type (which uses Quaternion.LookRotation to generate the rotation needed). You could have this ViewType be the default, then immediately switch to whatever first person ViewType you normally use.
 
I'm struggling with this a bit. I created my custom LookAtViewType, but I'm struggling with implementing the LookDirection() method properly. You mentioned the Third Person LookAt View Type, but I don't believe I have access to that. Would you be willing to share the appropriate snippet?
 
The basic idea would be to use Quaternion.LookRotation to generate the rotation needed. So your Rotate method could do something like:

C#:
var targetDirection = targetObject.transform.position - m_Character.transform.position;
var rotation = Quaternion.LookRotation(targetDirection, Vector3.up);
return rotation;

Obviously this would immediately snap the rotation to look at targetObject, so in the end you'd probably want to do some lerping of some kind.
 
Thank you, that was very useful. So I've pretty much got this working. However -- I think it's different than what I'm seeking.

It will indeed set where the cam is looking, so I can start the camera looking at an item of interest when the game starts. However, as soon as I then change to the regular "First Person Combat" view type (so the player can play the game as usual), the view snaps back to the default "look straight ahead" view. I want the player's actual "playable" view type to be on the item of interest. Effectively mimicking if they had started the game, then used the mouse to look at the item. It's like mimicking what the player does manually with the mouse, but setting the initial view direction. Hopefully that's clear.

How can I achieve this?
 
You could instead simply manually call the Rotate method of the view type. You'd need to first calculate the angle needed to rotate by to face the target object (Vector3.Angle might help here). E.g. cameraController.ActiveViewType.Rotate(degrees, 0, true);
 
Working on getting this working. I think I have to do a Vector2.Angle on the X/Z plane to get the "horizontal" movement, and then on the... hmm X/Y for the vertical?

I have degrees calculated and ready to test, but the Rotate() method seems to take between -1 and 1. Is that % of 360 degrees? So 90 degrees would be 0.25? Just a guess. Please let me know.
 
I believe that comment is outdated - the horizontalMovement/verticalMovement values correspond to the angles to rotate.
 
Top