Author Topic: [Feature Request] God view mode in VoxelPlayFirstPersonController  (Read 522 times)

sweatyc

  • Newbie
  • *
  • Posts: 7
    • View Profile
We wanted to transit player's first person view, to a top-down God mode view, in the Minecraft demo.



I found that it seems easier to change orbitMode code for that (since I'm not interested in orbitMode):

1. disable the rotation update in orbitMode and while switching in RotateView():
Code
if (!orbitMode && !switching) // HACK: do not rotate while orbit mode or switching
    mouseLook.LookRotation (transform, m_Camera.transform, orbitMode, lookAt, switchingLapsed);

2. add public function to expose rotations cached in MouseLook.cs:
Code
public Vector3 GetCharacterEulerAngles()
{
    return m_CharacterTargetRot.eulerAngles;
}
public Vector3 GetCameraEulerAngles()
{
    return m_CameraTargetRot.eulerAngles;
}

3. Now I can add function in VoxelPlayFirstPersonController, to use LeanTween to transit player's view to god move view, or go backward:
Code
public void ToggleGodMode()
{
SetOrbitMode(!orbitMode);
if (orbitMode) {
m_Jumping = false; // HACK: make sure jumping is off, otherwise it fall back to ground after zoom out while jumping
LeanTween.moveLocalY(gameObject, maxDistance - 1, switchDuration); // Move the character up
LeanTween.rotateY(gameObject, 0, switchDuration); // Reset the character rotation
LeanTween.rotateX(m_Camera.gameObject, 90, switchDuration); // Rotate camera so that it faces down
} else {
isFlying = false; // Make it fall back to ground
LeanTween.rotateY(gameObject, mouseLook.GetCharacterEulerAngles().y, switchDuration); // Reset back to the previous character rotation
LeanTween.rotateX(m_Camera.gameObject, mouseLook.GetCameraEulerAngles().x, switchDuration); // Reset back to the previous camera rotation
}
}

Not sure if it's a popular feature but would be great to see it. May be adding Enum ViewMode having FirstPersonMode, OrbitMode, GodMode, so there will be a function SetViewMode(ViewMode viewMode) to easily switch around.
« Last Edit: June 27, 2018, 04:35:49 AM by Kronnect »

Kronnect

  • Administrator
  • Hero Member
  • *****
  • Posts: 4900
    • View Profile
Re: [Feature Request] God view mode in VoxelPlayFirstPersonController
« Reply #1 on: April 27, 2018, 12:57:56 AM »
Sounds great! Definitely adding this feature in future updates.