|
Post by archieandrews on Mar 24, 2019 14:12:50 GMT
Hi What would be the basic code to be able to access the current camera state?
I would like to assign my D Pad to be able to raise/lower and zoom in/out the current camera on the fly.
How can I call/access the current camera state height and distance settings?
TY
|
|
|
Post by archieandrews on Mar 24, 2019 15:59:59 GMT
Trying to use: using Invector.vCamera;
Then ...
public vThirdPersonCamera vCamera;
vCamera.currentState.height = 20
Height changes but then goes back to original position
|
|
|
Post by archieandrews on Mar 27, 2019 14:03:04 GMT
Any help please ?
|
|
cyhak
Full vMember
Posts: 80
|
Post by cyhak on Mar 30, 2019 7:44:34 GMT
It resets in the next frame try in Update () method or fixed update...
|
|
|
Post by Invector on Apr 1, 2019 17:16:20 GMT
You can do that without scripting, by just adding a trigger to change the CameraState. We have examples of that in the vMansion demo scene
|
|
|
Post by archieandrews on Apr 2, 2019 23:03:20 GMT
Invector: I don't a trigger. I want to be able to edit the values of the current camera. Fact is I can edit them directly whilst in play mode per the graphic I attached prior. IF I can manually edit them there and they stay set then logic tells me I should be able to code such. I want the player to be able to move the camera setting to suit their preference. My game is not actually a game per se it is to create camera shots for cartoon film making. Triggers are of no use in this concept. Therefore I ask again how can I code such??
My current code in the update is ...
void Update () { CamDistance = Input.GetAxis("D-Pad Horizontal"); CamHeight = Input.GetAxis("D-Pad Vertical");
// Check if user activates Teleport button. If so launch UI.
if (Input.GetButtonDown("Back") || Input.GetKeyUp("t")) { TeleportUI.SetActive(true); // Deselect and reselect first button to correctly display highlight after enabling parent GO EventSystem es = GameObject.Find("EventSystem").GetComponent<EventSystem>(); es.SetSelectedGameObject(null); es.SetSelectedGameObject(es.firstSelectedGameObject);
} if (TeleportUI.activeSelf == false) // If UI not active allow player to move camera position { if (CamDistance != 0 ) { vCamera.currentState.defaultDistance = vCamera.currentState.defaultDistance + CamDistance/10; }
if (CamHeight != 0) { vCamera.currentState.height = 20;// vCamera.currentState.height + CamHeight; vCamera.distance = 20; } }
}
|
|
|
Post by archieandrews on Apr 2, 2019 23:08:21 GMT
It resets in the next frame try in Update () method or fixed update... Thanks chak
For some reason the values do not stay they reset to default position. IF I manually edit the values of the camera within the editor during game play they stay as I set them. That's what I'm trying to achieve in my code.
My objective is to move the camera up/down or forwards/backwards in small increments whilst user holds down one of the D pad buttons.
|
|
|
Post by Invector on Apr 3, 2019 14:42:00 GMT
You need to pass the value directly and increase/decrease the myNewValue via input, like this:
void Update () { myCamera.currentState.defaultDistance = myNewValue ;
if (Input.GetKeyDown(KeyCode.KeypadPlus)) myNewValue += 1f;
if (Input.GetKeyDown(KeyCode.KeypadMinus)) myNewValue -= 1f; }
|
|
|
Post by archieandrews on May 9, 2019 10:33:23 GMT
This has still not answered my question. AGAIN How do I set these values in runtime .. I should not have to do it in an update statement (not efficient) it makes the camer jitter.
I should be able to set this value ONE TIME ANY TIME just the same as I can in the editor during play.
In case you're not understanding .. think of it this way .. I edit the hihglighted (yellow) values in the editor (screenshots) while the game is running and they react within the game play.
IF I can manually edit them in the editor during game play which I can !!, then logic tells me that I should be able to access these values direct.
Now please tell me how to access these values. What paramater should I be accessing. Lack of documentation !!!
|
|
|
Post by Invector on May 10, 2019 18:53:54 GMT
Ok, let's try this again... here are a few options:
- The currentState will interpolate the values to the lerpState you can change the value using the lerpState. directly:
tpCamera.lerpState.fov = "yourValue";
This way the current state value will be changed using lerp. (smooth transition)
-If you need immediate change (no smooth) you can apply the value to currentState and lerpState simultaneously.
tpCamera.lerpState.fov = "yourValue";
tpCamera.currentState.fov = "yourValue";
-If you need to store your changes in a build, you need to create a save load system to store values.
|
|
ara
New vMember
Posts: 22
|
Post by ara on Oct 25, 2019 1:51:34 GMT
Thanks, this answered the exact question that I had and was able to get my camera angle follows terrain working. Then I realised that the camera states that invector had was an even better solution. Still finding great features in this that make my development easier. Thanks.
|
|