playMaker

Author Topic: Get an angled camera's forward direction relative to the player's up direction?  (Read 2865 times)

Spazdaxx

  • Playmaker Newbie
  • *
  • Posts: 5
Hey guys, hope your projects are going well!

Odd question here: I have a player that walks around meshes like in Super Mario Galaxy. I have the player moving forward, camera working (Cinemachine free-look camera) and the player standing up relative to the surface normal it's standing on.

Though, I want to make the player face away from the camera at all times wherein forward is camera up, back is camera down, left is camera left, and right is camera right. Due to further offsetting this new forward direction with the analog stick axis angle, I cannot just parent the camera directly behind the player.

To do this, I think I need the camera's forward direction but only on the player's local XZ.

I tried getting the cross product of the camera's right and the vertex normal assuming this would get the forward direction I need. Sadly, that does not seem to be the case since it seems to include the angle the camera is pointing from thus, tilting the player forward like Michael Jackson in the Smooth Criminal music video.

Linked is a mockup of the angle I am trying to achieve (The black arrow) relative to the working camera and player:
Also, here is an image of my rotation state in Playmaker utilizing the cross product of the camera's right and the current vertex normal: https://drive.google.com/file/d/1srBbhwhpXX027e6AwPO-MlKOYWc_gO7X/view?usp=sharing

If you guys need more info, please let me know, and thanks for taking the time. This has been quite the stumper.
« Last Edit: October 15, 2019, 09:50:44 PM by Spazdaxx »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Hi,

1: use the action TransformDirection on the forward axis of the camer to get the forward axis of the camera in world space.

2: use InverseTransformDirection of that worldspace camera forward axis on the player transform to get the camera forward in local space in the player

3: you can then flatten that local vector setting the up value to 0, you end up with a vector in local space indicating where the player needs to go in local space.

Bye,

 Jean

Spazdaxx

  • Playmaker Newbie
  • *
  • Posts: 5
Wow, thanks for replying so quick! :)

Okay, I think I understand. Although I may not be doing it right since the camera and the player forwards do not stay aligned.

It seems that by getting the rotation local to the player and trying to rotate the player object at the same time causes the player to shake player left and right every other frame: https://drive.google.com/file/d/1DyX67-rcwRRBug7Cg2DhV3vlRKTgX8TN/view?usp=sharing

I tried to isolate things by just doing the three steps outlined above on flat ground (world up) without anything else but unfortunately the camera and player don't want to keep facing the same forward:

Hm.. would it be possible to use a Get Axis Vector component but instead of Map To Plane and Relative To being in world space, could it be relative to a game object instead?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Hi,

 You'll have to fiddle with it for sure, it's not easy to get these things right.

you need to understand what TransformDirection and InverseTransformdirection do, and then it will be easier to plan for features.

yes, you can get the get axis vector, use that as your direction when you use TransformDirection to express the input from local space to world space.

Bye,

 Jean