SchultzGames
Para tirar dúvidas, crie um tópico especifico na área "Dúvidas em Geral" e aguarde ser respondido. Evite comentar em tópicos não relacionados a sua dúvida :D
TÓPICOS RECENTES:
Tópico:
Postado em:
Postado por:
Arquivo jar não encontrado
OBJETO sendo detruído imediatamente mesmo com o...
Meu site de Modelos 3D
DÚVIDA - ao pressionar andar, o player parece cancelar a gravidade (VÍDEO)
[RESLVIDO] Unity - "transform.SetParent()" em 2 objetos move outros objetos
Dúvida sobre resoluções de tela
Duvida na AppleStore
pressionando a tecla abaixar, o player continua andando abaixado (2D).
Fala Pessoal! Saiu mais um trailer do jogo que venho desenvolvendo
[RESOLVIDO] passar de uma animação para a outra rapidamente pelo animator
Unity - PlayerPrefs n são apagados no Celular mesmo Reiniciando o Aparelho
Modeloes 3D do Site Sketchfab
Blender - Modelos Importados transparentes
[PEDIDO]Cololar jogo na loja play store
Como pegar um objeto e fazer ele aparecer em forma de Estamina no Inspector
Procuro Pessoas para Projeto
Algum tutorial de como fazer um app que receba fotos e q fiqu armazenado no
Procuro um time para um jogo de corrida
[RESOLVIDO] Botões de Ataque e Pular carrega duas animações ao mesmo tempo
DEATH ISLAND 0.2.5 SURVIVAL GAME 4 ANOS EM DESENVOLVIMENTO
Player travando na colisão com o chão Unity 2D
Como resolver vazamento de memoria?
Instanciar uma classe nos atributos de outra classe é uma boa prática?
Jogo multiplayer com steam
Unity - Renderizção com Câmera Jogo Lento e travando. Alguém pfv?!
Mini Quarteirão com Texturas 3D VENDA
Controle do braço e cabeça no fps
PRECISO FAZER QUE MEU GAME FIQUE ONLINE
Ativar o objeto correto em Clones.
[TUTORIAL] Como fazer um interruptor simples (Unity 2018)
Preciso de 20 testadores jogo mobile
O Labirinto II - Trailer Oficial
Ue posso divulgar meu game que ainda esta em criaçao aqui no forum?
[RESOLVIDO] Inverter o sprite para a direçao que o personagem anda.
Set Active não a reabiilitado C#
Build APK VR Google Cardbord com video.
[PROGRAMADOR FREELA] $$
Mais Um jogo!
Collider (mesh?)
[TUTORIAL] Deformar mesh com batidas (para objetos, veículos, etc)
WW2 Low poly Pack (Free)
Procuro freelancer
Novo Teaser do jogo Dark Age
Unity Admob Erro
Sombras estão quadradas na build
nao consigo fazer o player sentar no sofa alguem me ajuda
Unity - Ao mudar de scene, todas as Lights são deletadas
210 Linhas de código para inimigo é muito grande?
modelar avatar e skins para um jogo web
ShapeKeys do Blender para a Unity altera áreas próximas
COMO EVITAR QUE UM OBJETO (PLAYER,ITEM ETC...) ATRAVESSE UMA PAREDE.
Ajuda em Script de Verificação de Ação e Reação
unity Failed to load PlayerSettings (internal index #0). Most likely data f
Materiais do Blander não aparecem no MeshRendere do Objeto na Unity
Repetiçoes de Textura no Terreno
SERVER IS DOWN - UNITY+MSQL
Procuro programadores - Novo jogo
Problema com o MS VEHICLES
Preciso de ajuda com a Unity
Problema com vídeo em 360° na Unity
Problemas no MS Vehicles
unity- eventos na Animação com Armature/Bones vinda do blender não funciona
ajuda exibir resultados simulados em uma liga Game Unity
Unity - ParticleSystem não é redirecionado no rawimage no canvas
Como resolver o problema de "face orientation" no Blender.
[DÚVIDA] Tive um problema com meu Canvas
erro na Directional Light
Problemas com o Directional Light da Unity 3D
Novo jogo da franquia Sphere game em desenvolvimento
malha da roda não girando com wheel collider unity
Problemas com ambiguidade
Touch mobile
INVALID TOKEN
Como acessar o "HD Render Pipeline" do HDRP por script?
CHAT GPT PRA JOGO DE TIRO? comentem
Tutorial script inimigo segue e foge do player
Ainda vale a pena lançar Asset na Asset Store?
Ajuda com tabela de historico de pontuaçao.
[TUTORIAL] Entrar no carro estilo GTA
Como derrapar um Whell Collider
Como altertar o valor do "Asymptote Value" do Whell Collider via Script
Preciso de ajuda para substituir valor de variavel em outro script
Ajuda com Top Down Shooter utilizando Photon
Duvida com Netcode
[RESOLVIDO] Unity - Movendo a Câmera na Horizontal/Vertical com Touch
Alguém me ajuda com os anúncios pfv
Segundo Trailer do jogo Dark Age, Feliz Natal a todos!
Unity - ScrollRect, Viewport, Content - O Conteúdo ñ inicia no topo
Coleta de itens
Unity - Cadastro do email do jogador
[GRATIS] PACK DE MODELOS 3D PARA JOGO DE TERROR
Onde Conseguir músicas para meu Jogo?
error CS0246 em Script
Alguem teve ja esse problema?
[Projeto em Andamento] Draug, um jogo de hordas
DISPONIVEL PARA FAZER MODELOS 3D
Unity-Loja.Como os Jogadores terão acesso aos ítens comprados na PlayStore?
Bugando depois do Build.
Primeiro Trailer do jogo Dark Age
Qua Out 23, 2024 8:39 pm
Sex Out 18, 2024 4:05 pm
Dom Out 06, 2024 6:02 pm
Sáb Out 05, 2024 6:37 am
Qui Out 03, 2024 10:09 pm
Seg Set 30, 2024 9:25 am
Sáb Set 28, 2024 11:39 am
Seg Set 09, 2024 7:33 am
Dom Set 08, 2024 10:08 pm
Ter Set 03, 2024 11:59 am
Qua Ago 28, 2024 7:45 pm
Qua Ago 28, 2024 7:18 pm
Qua Ago 28, 2024 8:34 am
Dom Ago 25, 2024 8:37 pm
Sáb Ago 24, 2024 1:58 pm
Sex Ago 23, 2024 3:30 pm
Sex Ago 23, 2024 3:23 pm
Qua Ago 21, 2024 5:48 pm
Dom Ago 18, 2024 8:51 pm
Sex Ago 16, 2024 12:59 pm
Qua Ago 14, 2024 10:57 am
Sáb Ago 10, 2024 8:03 pm
Sex Ago 09, 2024 7:37 pm
Dom Ago 04, 2024 4:41 pm
Dom Ago 04, 2024 3:16 pm
Qui Jul 25, 2024 2:48 pm
Dom Jul 21, 2024 7:07 pm
Dom Jul 21, 2024 12:07 am
Sáb Jul 13, 2024 12:33 am
Qui Jun 27, 2024 5:49 pm
Qui Jun 20, 2024 12:30 pm
Dom Jun 09, 2024 7:43 pm
Dom Jun 09, 2024 2:16 pm
Seg Jun 03, 2024 11:39 am
Seg maio 27, 2024 12:45 pm
Seg maio 20, 2024 9:01 pm
Dom maio 19, 2024 3:08 pm
Sáb maio 18, 2024 11:46 am
Sáb maio 11, 2024 8:55 am
Qui maio 09, 2024 11:33 pm
Seg Abr 29, 2024 9:34 pm
Qui Abr 25, 2024 3:34 pm
Seg Abr 22, 2024 5:15 pm
Seg Abr 15, 2024 12:23 pm
Seg Abr 08, 2024 9:27 pm
Seg Abr 08, 2024 8:01 am
Sáb Abr 06, 2024 8:05 pm
Qui Abr 04, 2024 11:34 pm
Qui Abr 04, 2024 11:13 pm
Sex Mar 22, 2024 2:41 pm
Dom Mar 10, 2024 2:30 pm
Sex Mar 01, 2024 1:27 pm
Qui Fev 22, 2024 9:57 pm
Ter Fev 20, 2024 12:15 am
Seg Fev 19, 2024 1:06 pm
Seg Fev 12, 2024 1:56 pm
Seg Fev 12, 2024 1:17 pm
Dom Fev 11, 2024 8:55 pm
Dom Fev 11, 2024 11:16 am
Seg Fev 05, 2024 4:18 pm
Dom Fev 04, 2024 9:39 pm
Qua Jan 31, 2024 11:59 pm
Ter Jan 30, 2024 7:37 pm
Ter Jan 23, 2024 6:33 pm
Dom Jan 21, 2024 6:03 pm
Sáb Jan 20, 2024 7:03 pm
Sáb Jan 20, 2024 6:58 pm
Sáb Jan 20, 2024 6:39 pm
Sex Jan 19, 2024 8:40 am
Dom Jan 14, 2024 5:30 pm
Qua Jan 10, 2024 10:29 pm
Qua Jan 10, 2024 8:55 pm
Qua Jan 10, 2024 7:14 pm
Ter Jan 09, 2024 3:55 pm
Ter Jan 09, 2024 8:04 am
Sáb Jan 06, 2024 8:02 pm
Sex Jan 05, 2024 7:01 am
Sex Jan 05, 2024 12:12 am
Qui Jan 04, 2024 6:55 pm
Qui Jan 04, 2024 12:52 pm
Qui Jan 04, 2024 4:34 am
Ter Jan 02, 2024 11:48 pm
Dom Dez 31, 2023 7:25 pm
Qua Dez 27, 2023 5:44 pm
Qua Dez 27, 2023 3:08 pm
Sáb Dez 23, 2023 7:27 pm
Sáb Dez 23, 2023 5:06 pm
Qui Dez 21, 2023 8:10 pm
Seg Dez 18, 2023 2:04 pm
Sex Dez 15, 2023 5:11 pm
Qui Dez 14, 2023 9:13 pm
Qui Dez 14, 2023 2:47 pm
Qui Dez 14, 2023 1:48 pm
Qua Dez 13, 2023 8:58 pm
Ter Dez 12, 2023 2:32 pm
Seg Dez 11, 2023 1:53 pm
Qua Dez 06, 2023 8:13 pm
Sáb Dez 02, 2023 8:06 pm
Qui Nov 30, 2023 7:49 am



































































































Camera Height

3 participantes

Ir para baixo

DÚVIDA Camera Height

Mensagem por saccasolutions Seg maio 11, 2020 7:54 pm

I have attached the camera controller to a UMA Avatar but it focuses at the avatars feet. How can I adjust the height of the camera? Can this be done in the script?


Since the avatar is created at runtime I do not know how else I could attach the camera controller to anything else as part of the avatar.


Here you help?

saccasolutions
Iniciante
Iniciante

PONTOS : 1664
REPUTAÇÃO : 0
Respeito as regras : Camera Height  WvDYdlf

Ir para o topo Ir para baixo

DÚVIDA Re: Camera Height

Mensagem por Fagner Seg maio 11, 2020 9:22 pm

There's a "script" button in the page that you write your message, use it to paste your code.
In general, any camera controller look at the origin point of the transform, if is not a option to use a custom transform as position, you can add a offset in the code, like this:
Vector3 offset = new Vector3(0, 1 ,0)
This represents a height of 1 meter in Y axis. 
Now you can sum this vector to the position of the transform.
Look for a line like this;
Transform.LookAt(player/target)

Change to this:
Transform.LookAt(player/target + offset)
I hope this helps.
Fagner
Fagner
Moderador

Masculino PONTOS : 4444
REPUTAÇÃO : 667
Áreas de atuação : Modelagem 3D, Programação.
Respeito as regras : Camera Height  Aad8pUi

Ir para o topo Ir para baixo

DÚVIDA Re: Camera Height

Mensagem por saccasolutions Seg maio 11, 2020 10:53 pm

Fagner escreveu: There's a "script" button in the page that you write your message, use it to paste your code.
In general, any camera controller look at the origin point of the transform, if is not an option to use a custom transform as position, you can add a offset in the code, like this:
Vector3 offset = new Vector3 (0, 1, 0)
This represents a height of 1 meter in Y axis. 
Now you can sum this vector to the position of the transform.
Look for a line like this;
Transform.LookAt (player / target)

Change to this:
Transform.LookAt (player / target + offset)
I hope this helps.
I'm using the standard script and seeking to add this offset to the "Follow player" option. Here is the script. 

Código:
using System;
using UnityEngine;
using UnityEngine.UI;

[Serializable]
public class MSACC_CameraType {
   [Tooltip("A camera must be associated with this variable. The camera that is associated here, will receive the settings of this index.")]
   public Camera _camera;
   public enum TipoRotac{LookAtThePlayer, FirstPerson, FollowPlayer, Orbital, Stop, StraightStop, OrbitalThatFollows, ETS_StyleCamera, FlyCamera_OnlyWindows}
   [Tooltip("Here you must select the type of rotation and movement that camera will possess.")]
   public TipoRotac rotationType = TipoRotac.LookAtThePlayer;
   [Range(0.01f,1.0f)][Tooltip("Here you must adjust the volume that the camera attached to this element can perceive. In this way, each camera can perceive a different volume.")]
   public float volume = 1.0f;
}
[Serializable]
public class MSACC_CameraSetting {
   [Header("Configure Inputs")]
   [Tooltip("The input that will define the horizontal movement of the cameras.")]
   public string inputMouseX = "Mouse X";
   [Tooltip("The input that will define the vertical movement of the cameras.")]
   public string inputMouseY = "Mouse Y";
   [Tooltip("The input that allows you to zoom in or out of the camera.")]
   public string inputMouseScrollWheel = "Mouse ScrollWheel";
   [Tooltip("In this variable you can configure the key responsible for switching cameras.")]
   public KeyCode cameraSwitchKey = KeyCode.C;

   public enum UpdateMode {Update, FixedUpdate, LateUpdate};
   [Header("Update mode")]
   [Tooltip("Here it is possible to decide whether the motion of the cameras will be processed in the void Update, FixedUpdate or LateUpdate. The mode that best suits most situations is the 'LateUpdate'.")]
   public UpdateMode camerasUpdateMode = UpdateMode.LateUpdate;

   [Header("General settings")]
   [Tooltip("If this variable is checked, the script will automatically place the 'IgnoreRaycast' layer on the player when needed.")]
   public bool ajustTheLayers = true;
   [Tooltip("In this class you can configure the 'FirstPerson' style cameras.")]
   public MSACC_SettingsCameraFirstPerson firstPerson;
   [Tooltip("In this class you can configure the 'FollowPlayer' style cameras.")]
   public MSACC_SettingsCameraFollow followPlayer;
   [Tooltip("In this class you can configure the 'Orbital' style cameras.")]
   public MSACC_SettingsCameraOrbital orbital;
   [Tooltip("In this class you can configure the 'OrbitalThatFollows' style cameras.")]
   public MSACC_SettingsCameraOrbitalThatFollows OrbitalThatFollows;
   [Tooltip("In this class you can configure the 'ETS_StyleCamera' style cameras.")]
   public MSACC_SettingsCameraETS_StyleCamera ETS_StyleCamera;
   [Tooltip("In this class you can configure the 'FlyCamera' style cameras.")]
   public MSACC_SettingsFlyCamera FlyCamera_OnlyWindows;
}
[Serializable]
public class MSACC_SettingsCameraFirstPerson {
   [Header("Sensibility")]
   [Range(1,20)][Tooltip("Horizontal camera rotation sensitivity.")]
   public float sensibilityX = 10.0f;
   [Range(1,20)][Tooltip("Vertical camera rotation sensitivity.")]
   public float sensibilityY = 10.0f;
   [Range(0,1)][Tooltip("The speed with which the camera can approach your vision through the mouseScrool.")]
   public float speedScroolZoom = 0.5f;
   [Header("Limits")]
   [Range(0,360)][Tooltip("The highest horizontal angle that camera style 'FistPerson' camera can achieve.")]
   public float horizontalAngle = 65.0f;
   [Range(0,85)][Tooltip("The highest vertical angle that camera style 'FistPerson' camera can achieve.")]
   public float verticalAngle = 20.0f;
   [Range(0,40)][Tooltip("The maximum the camera can approximate your vision.")]
   public float maxScroolZoom = 30.0f;

   [Header("Custom Rotation Input")]
   [Tooltip("If this variable is true, the camera will only rotate when the key selected in the 'KeyToRotate' variable is pressed. If this variable is false, the camera can rotate freely, even without pressing any key.")]
   public bool rotateWhenClick = false;
   [Tooltip("Here you can select the button that must be pressed in order to rotate the camera.")]
   public string keyToRotate = "mouse 0";

   [Space(7)]
   [Tooltip("If this variable is true, the X-axis input will be inverted.")]
   public bool invertXInput = false;
   [Tooltip("If this variable is true, the X-axis input will be inverted.")]
   public bool invertYInput = false;
}
[Serializable]
public class MSACC_SettingsCameraFollow {
   [Header("Collision")]
   [Tooltip("If this variable is true, the camera ignores the colliders and crosses the walls freely.")]
   public bool ignoreCollision = false;

   [Header("Movement")]
   [Range(1,20)][Tooltip("The speed at which the camera can follow the player.")]
   public float displacementSpeed = 3.0f;

   [Header("Rotation")]
   [Tooltip("If this variable is true, the code makes a lookAt using quaternions.")]
   public bool customLookAt = false;
   [Range(1,30)][Tooltip("The speed at which the camera rotates as it follows and looks at the player.")]
   public float spinSpeedCustomLookAt = 15.0f;

   [Header("Use Scrool")]
   [Tooltip("If this variable is true, the 'FollowPlayer' camera style will have the player's distance affected by the mouse scrool. This will allow the player to zoom in or out of the camera.")]
   public bool useScrool = false;
   [Range(0.01f,2.0f)][Tooltip("The speed at which the player can zoom in and out of the camera.")]
   public float scroolSpeed = 1.0f;
   [Range(1,30)][Tooltip("The minimum distance the camera can be relative to the player.")]
   public float minDistance = 7.0f;
   [Range(1,200)][Tooltip("The maximum distance the camera can be relative to the player.")]
   public float maxDistance = 40.0f;
}
[Serializable]
public class MSACC_SettingsCameraOrbital {
   [Header("Settings")]
   [Range(0.01f,2.0f)][Tooltip("In this variable you can configure the sensitivity with which the script will perceive the movement of the X and Y inputs. ")]
   public float sensibility = 0.8f;
   [Range(0.01f,2.0f)][Tooltip("In this variable, you can configure the speed at which the orbital camera will approach or distance itself from the player when the mouse scrool is used.")]
   public float speedScrool = 1.0f;
   [Range(0.01f,2.0f)][Tooltip("In this variable, you can configure the speed at which the orbital camera moves up or down.")]
   public float speedYAxis = 0.5f;

   [Header("Limits")]
   [Range(3.0f,20.0f)][Tooltip("In this variable, you can set the minimum distance that the orbital camera can stay from the player.")]
   public float minDistance = 5.0f;
   [Range(20.0f,1000.0f)][Tooltip("In this variable, you can set the maximum distance that the orbital camera can stay from the player.")]
   public float maxDistance = 50.0f;
   [Range(-85,0)][Tooltip("In this variable it is possible to define the minimum angle that the camera can reach on the Y axis")]
   public float minAngleY = 0.0f;
   [Range(0,85)][Tooltip("In this variable it is possible to define the maximum angle that the camera can reach on the Y axis")]
   public float maxAngleY = 80.0f;
   [Tooltip("If this variable is true, the camera ignores the colliders and crosses the walls freely.")]
   public bool ignoreCollision = false;

   [Header("Custom Rotation Input")]
   [Tooltip("If this variable is true, the camera will only rotate when the key selected in the 'KeyToRotate' variable is pressed. If this variable is false, the camera can rotate freely, even without pressing any key.")]
   public bool rotateWhenClick = false;
   [Tooltip("Here you can select the button that must be pressed in order to rotate the camera.")]
   public string keyToRotate = "mouse 0";

   [Space(7)]
   [Tooltip("If this variable is true, the X-axis input will be inverted.")]
   public bool invertXInput = false;
   [Tooltip("If this variable is true, the X-axis input will be inverted.")]
   public bool invertYInput = false;
}
[Serializable]
public class MSACC_SettingsCameraOrbitalThatFollows {
   [Header("Settings(Follow)")]
   [Range(1,20)][Tooltip("The speed at which the camera can follow the player.")]
   public float displacementSpeed = 5.0f;
   [Tooltip("If this variable is true, the code makes a lookAt using quaternions.")]
   public bool customLookAt = false;
   [Range(1,30)][Tooltip("The speed at which the camera rotates as it follows and looks at the player.")]
   public float spinSpeedCustomLookAt = 15.0f;

   [Header("Settings(Orbital)")]
   [Range(0.01f,2.0f)][Tooltip("In this variable you can configure the sensitivity with which the script will perceive the movement of the X and Y inputs. ")]
   public float sensibility = 0.8f;
   [Range(0.01f,2.0f)][Tooltip("In this variable, you can configure the speed at which the orbital camera will approach or distance itself from the player when the mouse scrool is used.")]
   public float speedScrool = 1.0f;
   [Range(0.01f,2.0f)][Tooltip("In this variable, you can configure the speed at which the orbital camera moves up or down.")]
   public float speedYAxis = 0.5f;
   [Range(3.0f,20.0f)][Tooltip("In this variable, you can set the minimum distance that the orbital camera can stay from the player.")]
   public float minDistance = 5.0f;
   [Range(20.0f,1000.0f)][Tooltip("In this variable, you can set the maximum distance that the orbital camera can stay from the player.")]
   public float maxDistance = 50.0f;
   [Range(-85,0)][Tooltip("In this variable it is possible to define the minimum angle that the camera can reach on the Y axis")]
   public float minAngleY = 0.0f;
   [Range(0,85)][Tooltip("In this variable it is possible to define the maximum angle that the camera can reach on the Y axis")]
   public float maxAngleY = 80.0f;
   [Space(7)]
   [Tooltip("If this variable is true, the camera will only rotate when the key selected in the 'KeyToRotate' variable is pressed. If this variable is false, the camera can rotate freely, even without pressing any key.")]
   public bool rotateWhenClick = false;
   [Tooltip("Here you can select the button that must be pressed in order to rotate the camera.")]
   public string keyToRotate = "mouse 0";
   [Tooltip("If this variable is true, the X-axis input will be inverted.")]
   public bool invertXInput = false;
   [Tooltip("If this variable is true, the X-axis input will be inverted.")]
   public bool invertYInput = false;
   //
   public enum ResetTimeType { Time, Input_OnlyWindows }
   [Header("Settings(General)")]
   [Tooltip("In this variable it is possible to define how the control will be redefined for the camera that follows the player, through input or through a time.")]
   public ResetTimeType ResetControlType = ResetTimeType.Time;
   [Tooltip("If 'ResetControlType' is set to 'Input_OnlyWindows', the key that must be pressed to reset the control will be set by this variable.")]
   public KeyCode resetKey = KeyCode.Z;
   [Range(1.0f,50.0f)][Tooltip("If 'ResetControlType' is set to 'Time', the wait time for the camera to reset the control will be set by this variable.")]
   public float timeToReset = 8.0f;
   [Tooltip("If this variable is true, the camera ignores the colliders and crosses the walls freely.")]
   public bool ignoreCollision = false;
}
[Serializable]
public class MSACC_SettingsCameraETS_StyleCamera {
   [Header("Settings")]
   [Range(1,20)][Tooltip("Horizontal camera rotation sensitivity.")]
   public float sensibilityX = 10.0f;
   [Range(1,20)][Tooltip("Vertical camera rotation sensitivity.")]
   public float sensibilityY = 10.0f;
   [Range(0.5f,3.0f)][Tooltip("The distance the camera will move to the left when the mouse is also shifted to the left. This option applies only to cameras that have the 'ETS_StyleCamera' option selected.")]
   public float ETS_CameraShift = 1.0f;
   [Range(0,40)][Tooltip("The maximum the camera can approximate your vision.")]
   public float maxScroolZoom = 30.0f;
   [Range(0,1)][Tooltip("The speed with which the camera can approach your vision through the mouseScrool.")]
   public float speedScroolZoom = 0.5f;

   [Header("Custom Rotation Input")]
   [Tooltip("If this variable is true, the camera will only rotate when the key selected in the 'KeyToRotate' variable is pressed. If this variable is false, the camera can rotate freely, even without pressing any key.")]
   public bool rotateWhenClick = false;
   [Tooltip("Here you can select the button that must be pressed in order to rotate the camera.")]
   public string keyToRotate = "mouse 0";
   [Space(7)]
   [Tooltip("If this variable is true, the X-axis input will be inverted.")]
   public bool invertXInput = false;
   [Tooltip("If this variable is true, the X-axis input will be inverted.")]
   public bool invertYInput = false;
}
[Serializable]
public class MSACC_SettingsFlyCamera {
   [Header("Inputs")]
   [Tooltip("Here you can configure the 'Horizontal' inputs that should be used to move the camera 'CameraFly'.")]
   public string horizontalMove = "Horizontal";
   [Tooltip("Here you can configure the 'Vertical' inputs that should be used to move the camera 'CameraFly'.")]
   public string verticalMove = "Vertical";
   [Tooltip("Here you can configure the keys that must be pressed to accelerate the movement of the camera 'CameraFly'.")]
   public KeyCode speedKeyCode = KeyCode.LeftShift;
   [Tooltip("Here you can configure the key that must be pressed to move the camera 'CameraFly' up.")]
   public KeyCode moveUp = KeyCode.E;
   [Tooltip("Here you can configure the key that must be pressed to move the camera 'CameraFly' down.")]
   public KeyCode moveDown = KeyCode.Q;
   //
   [Header("Settings")]
   [Range(1,20)][Tooltip("Horizontal camera rotation sensitivity.")]
   public float sensibilityX = 10.0f;
   [Range(1,20)][Tooltip("Vertical camera rotation sensitivity.")]
   public float sensibilityY = 10.0f;
   [Range(1,100)][Tooltip("The speed of movement of this camera.")]
   public float movementSpeed = 20.0f;
   [Space(7)]
   [Tooltip("If this variable is true, the X-axis input will be inverted.")]
   public bool invertXInput = false;
   [Tooltip("If this variable is true, the X-axis input will be inverted.")]
   public bool invertYInput = false;
}

public class MSCameraController : MonoBehaviour {

   [Tooltip("Here you must associate the object that the cameras will follow. If you leave this variable empty, the cameras will follow the object in which this script was placed.")]
   public Transform target;

   [Space(7)][Tooltip("Here you must associate all the cameras that you want to control by this script, associating each one with an index and selecting your preferences.")]
   public MSACC_CameraType[] cameras = new MSACC_CameraType[0];
   [Tooltip("Here you can configure the cameras, deciding their speed of movement, rotation, zoom, among other options.")]
   public MSACC_CameraSetting CameraSettings;

   bool orbitalAtiv;
   bool orbital_AtivTemp;
   float rotacX = 0.0f;
   float rotacY = 0.0f;
   float tempoOrbit = 0.0f;
   float rotacXETS = 0.0f;
   float rotacYETS = 0.0f;

   Vector2 cameraRotationFly;
   bool changeCam;

   GameObject[] objPosicStopCameras;
   Quaternion[] originalRotation;
   GameObject[] originalPosition;
   Vector3[] originalPositionETS;
   float[] xOrbit;
   float[] yOrbit;
   float[] distanceFromOrbitalCamera;
   float[] initialFieldOfView;
   float[] camFollowPlayerDistance;

   int index = 0;
   int lastIndex = 0;

   Transform targetTransform;
   GameObject playerCamsObj;


   //global inputs
   [HideInInspector]
   public float _horizontalInputMSACC;
   [HideInInspector]
   public float _verticalInputMSACC;
   [HideInInspector]
   public float _scrollInputMSACC;
   [HideInInspector]
   public bool _enableMobileInputs;
   [HideInInspector]
   public int _mobileInputsIndex; // 0 = off,  1 = all,  2 = scroll buttons only

   void OnValidate (){
        if (cameras != null) {
            for (int x = 0; x < cameras.Length; x++) {
                if (cameras[x].volume == 0) {
                    cameras[x].volume = 1;
                }
            }
        }
   }

   void Awake(){

      if (target) {
         targetTransform = target;
      } else {
         targetTransform = transform;
      }

      GameObject temp = new GameObject ("PlayerCams");
      temp.transform.parent = targetTransform;
      objPosicStopCameras = new GameObject[cameras.Length];
      originalRotation = new Quaternion[cameras.Length];
      originalPosition = new GameObject[cameras.Length];
      originalPositionETS = new Vector3[cameras.Length];
      xOrbit = new float[cameras.Length];
      yOrbit = new float[cameras.Length];

      distanceFromOrbitalCamera = new float[cameras.Length];
      initialFieldOfView = new float[cameras.Length];
      camFollowPlayerDistance = new float[cameras.Length];

      changeCam = false;
      orbitalAtiv = false;
      orbital_AtivTemp = false;

      for (int x = 0; x < cameras.Length; x++) {
         if (cameras [x]._camera) {
            if (cameras [x].volume == 0) {
               cameras [x].volume = 1;
            }
            initialFieldOfView [x] = cameras [x]._camera.fieldOfView;

            if (cameras [x].rotationType == MSACC_CameraType.TipoRotac.FirstPerson) {
               cameras [x]._camera.transform.parent = temp.transform;
               originalRotation [x] = cameras [x]._camera.transform.localRotation;
            }


            if (cameras [x].rotationType == MSACC_CameraType.TipoRotac.FollowPlayer) {
               cameras [x]._camera.transform.parent = temp.transform;
               originalPosition [x] = new GameObject ("positionFollowPlayerCamera" + x);
               originalPosition [x].transform.parent = temp.transform;
               originalPosition [x].transform.position = cameras [x]._camera.transform.position;
               if (CameraSettings.ajustTheLayers) {
                  targetTransform.gameObject.layer = 2;
                  foreach (Transform trans in targetTransform.gameObject.GetComponentsInChildren<Transform>(true)) {
                     trans.gameObject.layer = 2;
                  }
               }
               camFollowPlayerDistance [x] = Vector3.Distance (cameras [x]._camera.transform.position, targetTransform.position);
               cam
            }

            if (cameras [x].rotationType == MSACC_CameraType.TipoRotac.Orbital) {
               cameras [x]._camera.transform.parent = temp.transform;
               cameras [x]._camera.transform.LookAt (target);
               xOrbit [x] = cameras [x]._camera.transform.eulerAngles.y;
               yOrbit [x] = cameras [x]._camera.transform.eulerAngles.x;
               if (CameraSettings.ajustTheLayers) {
                  targetTransform.gameObject.layer = 2;
                  foreach (Transform trans in targetTransform.gameObject.GetComponentsInChildren<Transform>(true)) {
                     trans.gameObject.layer = 2;
                  }
               }
            }
            distanceFromOrbitalCamera [x] = Vector3.Distance (cameras [x]._camera.transform.position, targetTransform.position);
            distanceFromOrbitalCamera [x] = Mathf.Clamp (distanceFromOrbitalCamera [x], CameraSettings.orbital.minDistance, CameraSettings.orbital.maxDistance);

            if (cameras [x].rotationType == MSACC_CameraType.TipoRotac.Stop) {
               cameras [x]._camera.transform.parent = temp.transform;
            }

            if (cameras [x].rotationType == MSACC_CameraType.TipoRotac.StraightStop) {
               cameras [x]._camera.transform.parent = temp.transform;
               objPosicStopCameras [x] = new GameObject ("positionStraightStopCamera" + x);
               objPosicStopCameras [x].transform.parent = cameras [x]._camera.transform;
               objPosicStopCameras [x].transform.localPosition = new Vector3 (0, 0, 1.0f);
               objPosicStopCameras [x].transform.parent = temp.transform;
            }

            if (cameras [x].rotationType == MSACC_CameraType.TipoRotac.OrbitalThatFollows) {
               cameras [x]._camera.transform.parent = temp.transform;
               xOrbit [x] = cameras [x]._camera.transform.eulerAngles.x;
               yOrbit [x] = cameras [x]._camera.transform.eulerAngles.y;

               originalPosition [x] = new GameObject ("positionCameraFollowPlayer" + x);
               originalPosition [x].transform.parent = temp.transform;
               originalPosition [x].transform.position = cameras [x]._camera.transform.position;

               if (CameraSettings.ajustTheLayers) {
                  targetTransform.gameObject.layer = 2;
                  foreach (Transform trans in targetTransform.gameObject.GetComponentsInChildren<Transform>(true)) {
                     trans.gameObject.layer = 2;
                  }
               }
            }

            if (cameras [x].rotationType == MSACC_CameraType.TipoRotac.ETS_StyleCamera) {
               cameras [x]._camera.transform.parent = temp.transform;
               originalRotation [x] = cameras [x]._camera.transform.localRotation;
               originalPositionETS [x] = cameras [x]._camera.transform.localPosition;
            }

            if (cameras [x].rotationType == MSACC_CameraType.TipoRotac.FlyCamera_OnlyWindows) {
               cameras [x]._camera.transform.parent = null;
            }

            if (cameras [x].rotationType == MSACC_CameraType.TipoRotac.LookAtThePlayer) {
               cameras [x]._camera.transform.parent = null;
            }

            AudioListener audListner = cameras [x]._camera.GetComponent<AudioListener> ();
            if (audListner == null) {
               cameras [x]._camera.transform.gameObject.AddComponent (typeof(AudioListener));
            }

         } else {
            Debug.LogWarning ("There is no camera associated with the index " + x);
         }
      }
      playerCamsObj = temp;
      //
      if (CameraSettings.followPlayer.minDistance > CameraSettings.followPlayer.maxDistance) {
         CameraSettings.followPlayer.minDistance = 15;
         CameraSettings.followPlayer.maxDistance = 15;
         Debug.LogWarning ("The minimum distance from the 'FollowPlayer' camera is greater than the maximum distance, and this may cause errors.");
      }
   }

   void Start(){
      index = 0;
      lastIndex = 0;
      _enableMobileInputs = false;
      EnableCameras (index);
   }

   void EnableCameras (int index){
      if (cameras.Length > 0) {
         changeCam = true;
         for (int x = 0; x < cameras.Length; x++) {
            if (cameras [x]._camera) {
               if (x == index) {
                  cameras [x]._camera.gameObject.SetActive (true);
                  //
                  if (cameras [x].rotationType == MSACC_CameraType.TipoRotac.FirstPerson) {
                     rotacX = 0.0f;
                     rotacY = 0.0f;
                  }
                  if (cameras [x].rotationType == MSACC_CameraType.TipoRotac.OrbitalThatFollows) {
                     tempoOrbit = 0.0f;
                  }
                  if (cameras [x].rotationType == MSACC_CameraType.TipoRotac.ETS_StyleCamera) {
                     rotacXETS = 0.0f;
                     rotacYETS = 0.0f;
                  }
                  if (cameras [x].rotationType == MSACC_CameraType.TipoRotac.FlyCamera_OnlyWindows) {
                     cameras [x]._camera.transform.position = cameras [lastIndex]._camera.transform.position;
                     cameraRotationFly = new Vector2(cameras [lastIndex]._camera.transform.eulerAngles.y, 0);
                  }
               } else {
                  cameras [x]._camera.gameObject.SetActive (false);
               }
            }
         }
      }
   }

   void ManageCameras(){
      if (changeCam) {
         changeCam = false;
         for (int x = 0; x < cameras.Length; x++) {
            if (cameras [x].rotationType == MSACC_CameraType.TipoRotac.FollowPlayer) {
               if (cameras [x]._camera.isActiveAndEnabled) {
                  cameras [x]._camera.transform.parent = null;
               } else {
                  cameras [x]._camera.transform.parent = playerCamsObj.transform;
               }
            }
            //
            if (cameras [x].rotationType == MSACC_CameraType.TipoRotac.Orbital || cameras [x].rotationType == MSACC_CameraType.TipoRotac.OrbitalThatFollows) {
               cameras [x]._camera.transform.LookAt (target);
               xOrbit [x] = cameras [x]._camera.transform.eulerAngles.y;
               yOrbit [x] = cameras [x]._camera.transform.eulerAngles.x;
               distanceFromOrbitalCamera [x] = Vector3.Distance (cameras [x]._camera.transform.position, targetTransform.position);
               distanceFromOrbitalCamera [x] = Mathf.Clamp (distanceFromOrbitalCamera [x], CameraSettings.orbital.minDistance, CameraSettings.orbital.maxDistance);
            }
         }

         //set on/off mobile inputs
         if (cameras [index].rotationType == MSACC_CameraType.TipoRotac.Stop || cameras [index].rotationType == MSACC_CameraType.TipoRotac.StraightStop ||
            cameras [index].rotationType == MSACC_CameraType.TipoRotac.LookAtThePlayer || cameras [index].rotationType == MSACC_CameraType.TipoRotac.FlyCamera_OnlyWindows) {
            _mobileInputsIndex = 0; // 0 = all mobile inputs off
         }
         if (cameras [index].rotationType == MSACC_CameraType.TipoRotac.FirstPerson || cameras [index].rotationType == MSACC_CameraType.TipoRotac.ETS_StyleCamera ||
            cameras [index].rotationType == MSACC_CameraType.TipoRotac.Orbital || cameras [index].rotationType == MSACC_CameraType.TipoRotac.OrbitalThatFollows) {
            _mobileInputsIndex = 1; // 1 = all mobile inputs on
         }
         if (cameras [index].rotationType == MSACC_CameraType.TipoRotac.FollowPlayer) {
            _mobileInputsIndex = 2; // 2 = scroll buttons only
         }
      }

      AudioListener.volume = cameras [index].volume;
      float timeScaleSpeed = Mathf.Clamp (1.0f / Time.timeScale, 0.01f, 1);
      switch (cameras[index].rotationType ) {
      case MSACC_CameraType.TipoRotac.Stop:
         //stop camera
         break;
      case MSACC_CameraType.TipoRotac.StraightStop:
         Quaternion linearRotation = Quaternion.LookRotation(objPosicStopCameras[index].transform.position - cameras [index]._camera.transform.position, Vector3.up);
         cameras [index]._camera.transform.rotation = Quaternion.Slerp(cameras [index]._camera.transform.rotation, linearRotation, Time.deltaTime * 15.0f);
         break;
      case MSACC_CameraType.TipoRotac.LookAtThePlayer:
         cameras [index]._camera.transform.LookAt (targetTransform.position);
         break;
      case MSACC_CameraType.TipoRotac.FirstPerson:
         //getInputs
         float xInput = _horizontalInputMSACC;
         float yInput = _verticalInputMSACC;
         if (CameraSettings.firstPerson.invertXInput) {
            xInput = -_horizontalInputMSACC;
         }
         if (CameraSettings.firstPerson.invertYInput) {
            yInput = -_verticalInputMSACC;
         }
         if (CameraSettings.firstPerson.rotateWhenClick) {
            if (Input.GetKey (CameraSettings.firstPerson.keyToRotate) || _enableMobileInputs) {
               rotacX += xInput * CameraSettings.firstPerson.sensibilityX;
               rotacY += yInput * CameraSettings.firstPerson.sensibilityY;
            }
         } else {
            rotacX += xInput * CameraSettings.firstPerson.sensibilityX;
            rotacY += yInput * CameraSettings.firstPerson.sensibilityY;
         }
         //
         rotacX = ClampAngle (rotacX, -CameraSettings.firstPerson.horizontalAngle, CameraSettings.firstPerson.horizontalAngle);
         rotacY = ClampAngle (rotacY, -CameraSettings.firstPerson.verticalAngle, CameraSettings.firstPerson.verticalAngle);
         Quaternion xQuaternion = Quaternion.AngleAxis (rotacX, Vector3.up);
         Quaternion yQuaternion = Quaternion.AngleAxis (rotacY, -Vector3.right);
         Quaternion _nextRot = originalRotation [index] * xQuaternion * yQuaternion;
         cameras [index]._camera.transform.localRotation = Quaternion.Lerp (cameras [index]._camera.transform.localRotation, _nextRot, Time.deltaTime * 10.0f * timeScaleSpeed);
         //fieldOfView
         cameras [index]._camera.fieldOfView -= _scrollInputMSACC * CameraSettings.firstPerson.speedScroolZoom * 50.0f;
         if (cameras [index]._camera.fieldOfView < (initialFieldOfView [index] - CameraSettings.firstPerson.maxScroolZoom)) {
            cameras [index]._camera.fieldOfView = (initialFieldOfView [index] - CameraSettings.firstPerson.maxScroolZoom);
         }
         if (cameras [index]._camera.fieldOfView > initialFieldOfView [index]) {
            cameras [index]._camera.fieldOfView = (initialFieldOfView [index]);
         }
         break;
      case MSACC_CameraType.TipoRotac.FollowPlayer:
         //move
         RaycastHit hitCamFollow;
         if (CameraSettings.followPlayer.useScrool) {
            float camLerpSpeed = Time.deltaTime * CameraSettings.followPlayer.displacementSpeed * (camFollowPlayerDistance [index] * 0.1f);
            camFollowPlayerDistance [index] = camFollowPlayerDistance [index] - _scrollInputMSACC * (CameraSettings.followPlayer.scroolSpeed * 50.0f);
            camFollowPlayerDistance [index] = Mathf.Clamp (camFollowPlayerDistance [index], CameraSettings.followPlayer.minDistance, CameraSettings.followPlayer.maxDistance);
            Vector3 direction = (targetTransform.position - originalPosition [index].transform.position).normalized;
            Vector3 finalPos = targetTransform.position - direction * camFollowPlayerDistance [index];
            //
            if (!Physics.Linecast (targetTransform.position, finalPos)) {
               cameras [index]._camera.transform.position = Vector3.Lerp (cameras [index]._camera.transform.position, finalPos, camLerpSpeed);
            } else if (Physics.Linecast (targetTransform.position, finalPos, out hitCamFollow)) {
               if (CameraSettings.followPlayer.ignoreCollision) {
                  cameras [index]._camera.transform.position = Vector3.Lerp (cameras [index]._camera.transform.position, finalPos, camLerpSpeed);
               } else {
                  cameras [index]._camera.transform.position = Vector3.Lerp (cameras [index]._camera.transform.position, hitCamFollow.point, camLerpSpeed);
               }
            }
         } else {
            if (!Physics.Linecast (targetTransform.position, originalPosition [index].transform.position)) {
               cameras [index]._camera.transform.position = Vector3.Lerp (cameras [index]._camera.transform.position, originalPosition [index].transform.position, Time.deltaTime * CameraSettings.followPlayer.displacementSpeed);
            } else if (Physics.Linecast (transform.position, originalPosition [index].transform.position, out hitCamFollow)) {
               if (CameraSettings.followPlayer.ignoreCollision) {
                  cameras [index]._camera.transform.position = Vector3.Lerp (cameras [index]._camera.transform.position, originalPosition [index].transform.position, Time.deltaTime * CameraSettings.followPlayer.displacementSpeed);
               } else {
                  cameras [index]._camera.transform.position = Vector3.Lerp (cameras [index]._camera.transform.position, hitCamFollow.point, Time.deltaTime * CameraSettings.followPlayer.displacementSpeed);
               }
            }
         }
         //rotation
         if (CameraSettings.followPlayer.customLookAt) {
            Quaternion nextRotation = Quaternion.LookRotation (targetTransform.position - cameras [index]._camera.transform.position, Vector3.up);
            cameras [index]._camera.transform.rotation = Quaternion.Slerp (cameras [index]._camera.transform.rotation, nextRotation, Time.deltaTime * CameraSettings.followPlayer.spinSpeedCustomLookAt);
         } else {
            cameras [index]._camera.transform.LookAt (targetTransform.position);
         }
         break;
      case MSACC_CameraType.TipoRotac.Orbital:
         //raycast hit
         RaycastHit hitCamOrbital;
         float minDistance = CameraSettings.orbital.minDistance;
         if (Physics.Linecast (targetTransform.position, cameras [index]._camera.transform.position, out hitCamOrbital)) {
            if (!CameraSettings.orbital.ignoreCollision) {
               distanceFromOrbitalCamera [index] = Vector3.Distance (targetTransform.position, hitCamOrbital.point);
               minDistance = Mathf.Clamp (distanceFromOrbitalCamera [index], minDistance * 0.5f, CameraSettings.orbital.maxDistance);
            }
         }
         //getInputs
         float xInputOrb = _horizontalInputMSACC;
         float yInputOrb = _verticalInputMSACC;
         if (CameraSettings.orbital.invertXInput) {
            xInputOrb = -_horizontalInputMSACC;
         }
         if (CameraSettings.orbital.invertYInput) {
            yInputOrb = -_verticalInputMSACC;
         }
         if (CameraSettings.orbital.rotateWhenClick) {
            if (Input.GetKey (CameraSettings.orbital.keyToRotate) || _enableMobileInputs) {
               xOrbit [index] += xInputOrb * (CameraSettings.orbital.sensibility * distanceFromOrbitalCamera [index]) / (distanceFromOrbitalCamera [index] * 0.5f);
               yOrbit [index] -= yInputOrb * CameraSettings.orbital.sensibility * (CameraSettings.orbital.speedYAxis * 10.0f);
            }
         } else {
            xOrbit [index] += xInputOrb * (CameraSettings.orbital.sensibility * distanceFromOrbitalCamera [index]) / (distanceFromOrbitalCamera [index] * 0.5f);
            yOrbit [index] -= yInputOrb * CameraSettings.orbital.sensibility * (CameraSettings.orbital.speedYAxis * 10.0f);
         }
         //move - rotation
         yOrbit [index] = ClampAngle (yOrbit [index], CameraSettings.orbital.minAngleY, CameraSettings.orbital.maxAngleY);
         Quaternion quatToEuler = Quaternion.Euler (yOrbit [index], xOrbit [index], 0);
         distanceFromOrbitalCamera [index] = Mathf.Clamp (distanceFromOrbitalCamera [index] - _scrollInputMSACC * (CameraSettings.orbital.speedScrool * 50.0f), minDistance, CameraSettings.orbital.maxDistance);
         Vector3 zPosition = new Vector3 (0.0f, 0.0f, -distanceFromOrbitalCamera [index]);
         Vector3 nextPosCam = quatToEuler * zPosition + targetTransform.position;
         Vector3 currentPosCam = cameras [index]._camera.transform.position;
         Quaternion camRotation = cameras [index]._camera.transform.rotation;
         cameras [index]._camera.transform.rotation = Quaternion.Lerp(camRotation, quatToEuler, Time.deltaTime * 5.0f * timeScaleSpeed);
         cameras [index]._camera.transform.position = Vector3.Lerp(currentPosCam, nextPosCam, Time.deltaTime * 5.0f * timeScaleSpeed);
         break;
      case MSACC_CameraType.TipoRotac.OrbitalThatFollows:
         float movXInput = 0.0f;
         float movYInput = 0.0f;
         float movZInput = _scrollInputMSACC;
         if (CameraSettings.OrbitalThatFollows.rotateWhenClick) {
            if (Input.GetKey (CameraSettings.OrbitalThatFollows.keyToRotate) || _enableMobileInputs) {
               movXInput = _horizontalInputMSACC;
               movYInput = _verticalInputMSACC;
               if (CameraSettings.OrbitalThatFollows.invertXInput) {
                  movXInput = -_horizontalInputMSACC;
               }
               if (CameraSettings.OrbitalThatFollows.invertYInput) {
                  movYInput = -_verticalInputMSACC;
               }
            }
         } else {
            movXInput = _horizontalInputMSACC;
            movYInput = _verticalInputMSACC;
            if (CameraSettings.OrbitalThatFollows.invertXInput) {
               movXInput = -_horizontalInputMSACC;
            }
            if (CameraSettings.OrbitalThatFollows.invertYInput) {
               movYInput = -_verticalInputMSACC;
            }
         }
         //
         if (movXInput > 0.0f || movYInput > 0.0f || movZInput > 0.0f) {
            orbitalAtiv = true;
            tempoOrbit = 0.0f;
            if (!orbital_AtivTemp) {
               orbital_AtivTemp = true;
               xOrbit [index] = cameras [index]._camera.transform.eulerAngles.y;
               yOrbit [index] = cameras [index]._camera.transform.eulerAngles.x;
            }
         } else {
            tempoOrbit += Time.deltaTime;
            if (tempoOrbit > CameraSettings.OrbitalThatFollows.timeToReset) {
               tempoOrbit = CameraSettings.OrbitalThatFollows.timeToReset + 0.1f;
            }
         }
         //
         switch (CameraSettings.OrbitalThatFollows.ResetControlType) {
         case MSACC_SettingsCameraOrbitalThatFollows.ResetTimeType.Time:
            if (tempoOrbit > CameraSettings.OrbitalThatFollows.timeToReset) {
               orbitalAtiv = false;
               orbital_AtivTemp = false;
            }
            break;
         case MSACC_SettingsCameraOrbitalThatFollows.ResetTimeType.Input_OnlyWindows:
            if (Input.GetKeyDown(CameraSettings.OrbitalThatFollows.resetKey)) {
               orbitalAtiv = false;
               orbital_AtivTemp = false;
            }
            break;
         }
         //
         RaycastHit hitCamOTS;
         if(orbitalAtiv == true){
            float _minDistance = CameraSettings.OrbitalThatFollows.minDistance;
            if (Physics.Linecast (targetTransform.position, cameras [index]._camera.transform.position, out hitCamOTS)) {
               if (!CameraSettings.OrbitalThatFollows.ignoreCollision) {
                  distanceFromOrbitalCamera [index] = Vector3.Distance (targetTransform.position, hitCamOTS.point);
                  _minDistance = Mathf.Clamp (distanceFromOrbitalCamera [index], _minDistance * 0.5f, CameraSettings.OrbitalThatFollows.maxDistance);
               }
            }
            xOrbit [index] += movXInput * (CameraSettings.OrbitalThatFollows.sensibility * distanceFromOrbitalCamera [index]) / (distanceFromOrbitalCamera [index] * 0.5f);
            yOrbit [index] -= movYInput * CameraSettings.OrbitalThatFollows.sensibility * (CameraSettings.OrbitalThatFollows.speedYAxis * 10.0f);
            yOrbit [index] = ClampAngle (yOrbit [index], CameraSettings.OrbitalThatFollows.minAngleY, CameraSettings.OrbitalThatFollows.maxAngleY);
            Quaternion quaterToEuler = Quaternion.Euler (yOrbit [index], xOrbit [index], 0);
            distanceFromOrbitalCamera [index] = Mathf.Clamp (distanceFromOrbitalCamera [index] - movZInput * (CameraSettings.OrbitalThatFollows.speedScrool * 50.0f), _minDistance, CameraSettings.OrbitalThatFollows.maxDistance);
            Vector3 _zPosition = new Vector3 (0.0f, 0.0f, -distanceFromOrbitalCamera [index]);
            Vector3 _camNewPos = quaterToEuler * _zPosition + targetTransform.position;
            Vector3 _camCurrentPos = cameras [index]._camera.transform.position;
            Quaternion camRot = cameras [index]._camera.transform.rotation;
            cameras [index]._camera.transform.rotation = Quaternion.Lerp (camRot, quaterToEuler, Time.deltaTime * 5.0f * timeScaleSpeed);
            cameras [index]._camera.transform.position = Vector3.Lerp (_camCurrentPos, _camNewPos, Time.deltaTime * 5.0f * timeScaleSpeed);
         } else {
            if (!Physics.Linecast (targetTransform.position, originalPosition [index].transform.position)) {
               cameras [index]._camera.transform.position = Vector3.Lerp (cameras [index]._camera.transform.position, originalPosition [index].transform.position, Time.deltaTime * CameraSettings.OrbitalThatFollows.displacementSpeed);
            }
            else if(Physics.Linecast(targetTransform.position, originalPosition [index].transform.position,out hitCamOTS)){
               if (CameraSettings.OrbitalThatFollows.ignoreCollision) {
                  cameras [index]._camera.transform.position = Vector3.Lerp (cameras [index]._camera.transform.position, originalPosition [index].transform.position, Time.deltaTime * CameraSettings.OrbitalThatFollows.displacementSpeed);
               }
               else {
                  cameras [index]._camera.transform.position = Vector3.Lerp(cameras [index]._camera.transform.position, hitCamOTS.point,Time.deltaTime * CameraSettings.OrbitalThatFollows.displacementSpeed);
               }
            }
            //
            if (CameraSettings.OrbitalThatFollows.customLookAt) {
               Quaternion quatLookRot = Quaternion.LookRotation (targetTransform.position - cameras [index]._camera.transform.position, Vector3.up);
               cameras [index]._camera.transform.rotation = Quaternion.Slerp (cameras [index]._camera.transform.rotation, quatLookRot, Time.deltaTime * CameraSettings.OrbitalThatFollows.spinSpeedCustomLookAt);
            } else {
               cameras [index]._camera.transform.LookAt (targetTransform.position);
            }
         }
         break;
      case MSACC_CameraType.TipoRotac.ETS_StyleCamera:
         float xInputEts = _horizontalInputMSACC;
         float yInputEts = _verticalInputMSACC;
         if (CameraSettings.ETS_StyleCamera.invertXInput) {
            xInputEts = -_horizontalInputMSACC;
         }
         if (CameraSettings.ETS_StyleCamera.invertYInput) {
            yInputEts = -_verticalInputMSACC;
         }
         if (CameraSettings.ETS_StyleCamera.rotateWhenClick) {
            if (Input.GetKey (CameraSettings.ETS_StyleCamera.keyToRotate) || _enableMobileInputs) {
               rotacXETS += xInputEts * CameraSettings.ETS_StyleCamera.sensibilityX;
               rotacYETS += yInputEts * CameraSettings.ETS_StyleCamera.sensibilityY;
            }
         } else {
            rotacXETS += xInputEts * CameraSettings.ETS_StyleCamera.sensibilityX;
            rotacYETS += yInputEts * CameraSettings.ETS_StyleCamera.sensibilityY;
         }
         Vector3 newPositionETS = new Vector3 (originalPositionETS [index].x + Mathf.Clamp (rotacXETS / 50 + (CameraSettings.ETS_StyleCamera.ETS_CameraShift/3.0f), -CameraSettings.ETS_StyleCamera.ETS_CameraShift, 0), originalPositionETS [index].y, originalPositionETS [index].z);
         cameras [index]._camera.transform.localPosition = Vector3.Lerp (cameras [index]._camera.transform.localPosition, newPositionETS, Time.deltaTime * 10.0f);
         rotacXETS = ClampAngle (rotacXETS, -180, 80);
         rotacYETS = ClampAngle (rotacYETS, -60, 60);
         Quaternion _xQuaternion = Quaternion.AngleAxis (rotacXETS, Vector3.up);
         Quaternion _yQuaternion = Quaternion.AngleAxis (rotacYETS, -Vector3.right);
         Quaternion nextRot = originalRotation [index] * _xQuaternion * _yQuaternion;
         cameras [index]._camera.transform.localRotation = Quaternion.Lerp (cameras [index]._camera.transform.localRotation, nextRot, Time.deltaTime * 10.0f * timeScaleSpeed);
         //fieldOfView
         cameras [index]._camera.fieldOfView -= _scrollInputMSACC * CameraSettings.ETS_StyleCamera.speedScroolZoom * 50.0f;
         if (cameras [index]._camera.fieldOfView < (initialFieldOfView [index] - CameraSettings.ETS_StyleCamera.maxScroolZoom)) {
            cameras [index]._camera.fieldOfView = (initialFieldOfView [index] - CameraSettings.ETS_StyleCamera.maxScroolZoom);
         }
         if (cameras [index]._camera.fieldOfView > initialFieldOfView [index]) {
            cameras [index]._camera.fieldOfView = (initialFieldOfView [index]);
         }
         break;
      case MSACC_CameraType.TipoRotac.FlyCamera_OnlyWindows:
         float xInputFly = _horizontalInputMSACC;
         float yInputFly = _verticalInputMSACC;
         if (CameraSettings.FlyCamera_OnlyWindows.invertXInput) {
            xInputFly = -_horizontalInputMSACC;
         }
         if (CameraSettings.FlyCamera_OnlyWindows.invertYInput) {
            yInputFly = -_verticalInputMSACC;
         }
         //
         cameraRotationFly.x += xInputFly * CameraSettings.FlyCamera_OnlyWindows.sensibilityX * 15 * Time.deltaTime;
         cameraRotationFly.y += yInputFly * CameraSettings.FlyCamera_OnlyWindows.sensibilityY * 15 * Time.deltaTime;
         cameraRotationFly.y = Mathf.Clamp (cameraRotationFly.y, -90, 90);
         cameras [index]._camera.transform.rotation = Quaternion.AngleAxis (cameraRotationFly.x, Vector3.up);
         cameras [index]._camera.transform.rotation *= Quaternion.AngleAxis (cameraRotationFly.y, Vector3.left);
         //
         float speedCamFly = CameraSettings.FlyCamera_OnlyWindows.movementSpeed;
         if (Input.GetKey (CameraSettings.FlyCamera_OnlyWindows.speedKeyCode)) {
            speedCamFly *= 3.0f;
         }
         cameras [index]._camera.transform.position += cameras [index]._camera.transform.right * speedCamFly * Input.GetAxis(CameraSettings.FlyCamera_OnlyWindows.horizontalMove) * Time.deltaTime;
         cameras [index]._camera.transform.position += cameras [index]._camera.transform.forward * speedCamFly * Input.GetAxis(CameraSettings.FlyCamera_OnlyWindows.verticalMove) * Time.deltaTime;
         //
         if(Input.GetKey(CameraSettings.FlyCamera_OnlyWindows.moveUp)){
            cameras [index]._camera.transform.position += Vector3.up * speedCamFly * Time.deltaTime;
         }
         if(Input.GetKey(CameraSettings.FlyCamera_OnlyWindows.moveDown)){
            cameras [index]._camera.transform.position -= Vector3.up * speedCamFly * Time.deltaTime;
         }
         break;
      }
   }

   public static float ClampAngle (float angle, float min, float max){
      if (angle < -360F) { angle += 360F; }
      if (angle > 360F) { angle -= 360F; }
      return Mathf.Clamp (angle, min, max);
   }
   
   public void MSADCCChangeCameras(){ //use this void to change cameras using buttons
      if (Time.timeScale > 0) {
         if (index < (cameras.Length - 1)) {
            lastIndex = index;
            index++;
            EnableCameras (index);
         } else if (index >= (cameras.Length - 1)) {
            lastIndex = index;
            index = 0;
            EnableCameras (index);
         }
      }
   }

   void Update(){
      
      // Get inputs
      if (!_enableMobileInputs) {
         _horizontalInputMSACC = Input.GetAxis (CameraSettings.inputMouseX);
         _verticalInputMSACC = Input.GetAxis (CameraSettings.inputMouseY);
         _scrollInputMSACC = Input.GetAxis (CameraSettings.inputMouseScrollWheel);
      } else {
         //GetComponent<MSCameraController>()._horizontalInputMSACC = InputX;
         //GetComponent<MSCameraController>()._verticalInputMSACC = InputY;
         //GetComponent<MSCameraController>()._scrollInputMSACC = InputScroll;
      }
      _horizontalInputMSACC = Mathf.Clamp (_horizontalInputMSACC, -1, 1);
      _verticalInputMSACC = Mathf.Clamp (_verticalInputMSACC, -1, 1);
      _scrollInputMSACC = Mathf.Clamp (_scrollInputMSACC, -1, 1);
      //


      //camera switch key
      if (!_enableMobileInputs) {
         if (Time.timeScale > 0) {
            if (Input.GetKeyDown (CameraSettings.cameraSwitchKey) && index < (cameras.Length - 1)) {
               lastIndex = index;
               index++;
               EnableCameras (index);
            } else if (Input.GetKeyDown (CameraSettings.cameraSwitchKey) && index >= (cameras.Length - 1)) {
               lastIndex = index;
               index = 0;
               EnableCameras (index);
            }
         }
      }


      //update cameras
      if (CameraSettings.camerasUpdateMode == MSACC_CameraSetting.UpdateMode.Update) {
         if (cameras.Length > 0 && Time.timeScale > 0) {
            if (cameras [index]._camera) {
               ManageCameras ();
            }
         }
      }
   }

   void LateUpdate(){
      //update cameras
      if (CameraSettings.camerasUpdateMode == MSACC_CameraSetting.UpdateMode.LateUpdate) {
         if (cameras.Length > 0 && Time.timeScale > 0) {
            if (cameras [index]._camera) {
               ManageCameras ();
            }
         }
      }
   }

   void FixedUpdate(){
      //update cameras
      if (CameraSettings.camerasUpdateMode == MSACC_CameraSetting.UpdateMode.FixedUpdate) {
         if (cameras.Length > 0 && Time.timeScale > 0) {
            if (cameras [index]._camera) {
               ManageCameras ();
            }
         }
      }
   }
}

saccasolutions
Iniciante
Iniciante

PONTOS : 1664
REPUTAÇÃO : 0
Respeito as regras : Camera Height  WvDYdlf

Ir para o topo Ir para baixo

DÚVIDA Re: Camera Height

Mensagem por Fagner Seg maio 11, 2020 11:16 pm

I'm on my phone, it's hard to tell you the number of the line, but after the class name, there a property called target, you can declare your Vector3 offset after that. 
In the ManageCameras()
There's a line:
camera[x]._camera.transform.LookAt(target);
Just change the code adding a +offset.

You should look if there's another line like this one, and change the code too, use the search in your code editor (LookAt) 

Another option is to use a gameobject as target, drag it to the avatar hierarchy, preferably being the first child object. 
Look at the Awake () function, you can set the target using:
Target = transform.GetChild(index of object in hierarchy):

@MarcosSchultz, dá uma olhada aqui, veja se é só isso mesmo
Fagner
Fagner
Moderador

Masculino PONTOS : 4444
REPUTAÇÃO : 667
Áreas de atuação : Modelagem 3D, Programação.
Respeito as regras : Camera Height  Aad8pUi

Ir para o topo Ir para baixo

DÚVIDA Re: Camera Height

Mensagem por MarcosSchultz Ter maio 12, 2020 3:07 am

Hello. The code has a variable in the inspector called 'Target'. It is the first variable that appears. Just associate in this variable the object that the camera must follow.

Try to create an empty object (your player's child) and adjust it to the position of your player's head, and after that, associate this object in the 'target' variable.
MarcosSchultz
MarcosSchultz
Administrador

Masculino PONTOS : 64986
REPUTAÇÃO : 2654
Idade : 28
Áreas de atuação : Administrador do fórum
Respeito as regras : Camera Height  Aad8pUi

https://www.schultzgames.com

Ir para o topo Ir para baixo

DÚVIDA Re: Camera Height

Mensagem por saccasolutions Ter maio 12, 2020 11:03 pm

MarcosSchultz escreveu:Hello. The code has a variable in the inspector called 'Target'. It is the first variable that appears. Just associate in this variable the object that the camera must follow.

Try to create an empty object (your player's child) and adjust it to the position of your player's head, and after that, associate this object in the 'target' variable.
Yes, except I am using an UMA avatar with an idle animation so the camera moves and sways with any body part I try and attach the camera to.

saccasolutions
Iniciante
Iniciante

PONTOS : 1664
REPUTAÇÃO : 0
Respeito as regras : Camera Height  WvDYdlf

Ir para o topo Ir para baixo

DÚVIDA Re: Camera Height

Mensagem por saccasolutions Ter maio 12, 2020 11:08 pm

Fagner escreveu: I'm on my phone, it's hard to tell you the number of the line, but after the class name, there a property called target, you can declare your Vector3 offset after that. 
In the ManageCameras ()
There's a line:
camera [x] ._ camera.transform.LookAt (target);
Just change the code adding a + offset.

You should look if there's another line like this one, and change the code too, use the search in your code editor (LookAt) 

Another option is to use a gameobject as target, drag it to the avatar hierarchy, preferably being the first child object . 
Look at the Awake () function, you can set the target using:
Target = transform.GetChild (index of object in hierarchy):

@MarcosSchultz, take a look here, see if that's it
i found the line of the code, however I am a VERY new C programmer. Can you help with the correct syntax for the offset?

I'm thinking it could go here:
Código:
case MSACC_CameraType.TipoRotac.LookAtThePlayer:
         cameras [index]._camera.transform.LookAt (targetTransform.position);
            
         break;

or where you suggested (using follow player), somewhere here:
Código:
if (cameras [x].rotationType == MSACC_CameraType.TipoRotac.FollowPlayer) {
               cameras [x]._camera.transform.parent = temp.transform;
               originalPosition [x] = new GameObject ("positionFollowPlayerCamera" + x);
               originalPosition [x].transform.parent = temp.transform;
               originalPosition [x].transform.position = cameras [x]._camera.transform.position;
               if (CameraSettings.ajustTheLayers) {
                  targetTransform.gameObject.layer = 2;
                  foreach (Transform trans in targetTransform.gameObject.GetComponentsInChildren<Transform>(true)) {
                     trans.gameObject.layer = 2;
                  }
               }
               camFollowPlayerDistance [x] = Vector3.Distance (cameras [x]._camera.transform.position, targetTransform.position);

saccasolutions
Iniciante
Iniciante

PONTOS : 1664
REPUTAÇÃO : 0
Respeito as regras : Camera Height  WvDYdlf

Ir para o topo Ir para baixo

DÚVIDA Re: Camera Height

Mensagem por saccasolutions Qua maio 13, 2020 12:08 am

Ok so that was easy! I thought maybe I would need to hardcose the coordinates, I did not realize it would add the editing to the editor! So... that gives me the ability to tilt the camera up, but how do I RAISE it? The camera itself is still sitting at the same level of the avatars feet.

saccasolutions
Iniciante
Iniciante

PONTOS : 1664
REPUTAÇÃO : 0
Respeito as regras : Camera Height  WvDYdlf

Ir para o topo Ir para baixo

DÚVIDA Re: Camera Height

Mensagem por Fagner Qua maio 13, 2020 3:41 am

I've made a simple script to add the offset on the LateUpdate() and restore the original position On Update(). this should work with MarcosSchultz original script.
You need to change your script execution order to make sure my script is the last executed.

https://docs.unity3d.com/Manual/class-MonoManager.html

Camera Height  ZP7kp36

Código:
using UnityEngine;

public class CameraOffset : MonoBehaviour
{
    public Transform cameraT;
    public Transform target;
    public Vector3 offsetCam, offsetTarget;

    private Vector3 lastposition;
    private Quaternion lastRotation;

    private void Update()
    {
        cameraT.position = lastposition;
        cameraT.rotation = lastRotation;
    }

    private void LateUpdate()
    {
        lastposition = cameraT.position;
        lastRotation = cameraT.rotation;

        cameraT.position += offsetCam;
        cameraT.LookAt(target.position + offsetTarget);
    }
}

Fagner
Fagner
Moderador

Masculino PONTOS : 4444
REPUTAÇÃO : 667
Áreas de atuação : Modelagem 3D, Programação.
Respeito as regras : Camera Height  Aad8pUi

Ir para o topo Ir para baixo

Ir para o topo

- Tópicos semelhantes

 
Permissões neste sub-fórum
Não podes responder a tópicos