edited April 2017 in ORK Support
i've got two types of battle in my current game: in situ (i.e. those that take place in the location where they were initiated), and arena-based (i.e. those that take place in a different location from where they were initiated, and then return to the scene from which they were initiated after the battle is over). i'm using PhatRobat's RPG Camera as my camera controller

the camera, and the two battle types are all working ok under normal conditions, and everything works as expected for in situ battles

however, when an arena battle has finished, and the game returns to the point at which the battle was initiated, then the RPG Camera is left pointing in the wrong direction, i think it points in the direction it was in when the level originally loaded. (once an in situ battle has finished there's no such problem however - the RPG Camera points in the correct direction once the battle ends)

i think this is an issue with the RPG Camera, because the same thing happens with scene changes. with those, fortunately all my scenes are simply linked in the four cardinal directions (N, S, E, W), so i store which of those directions is used for the scene change, and then, after the scene has changed, adjust the camera angle accordingly (to an x of 0, 90, 180, or 270 degrees)

that works ok in context, but i've only done it that way because i couldn't see any way of doing a "Change Fields" for the camera component to anything other than hard-coded values

what i really want to do with these arena battles is to store the RPG Camera's x rotation before the battle, and then restore it after the battle has finished, but i can't quite see how to do that. and perhaps there's a better way to do this anyway?
Post edited by HarryOminous on
  • Best way to do this would be to add that to the camera's script, e.g. store it in the OnDestroy function and restore it in the Start, Awake or OnEnable function. That way the camera control would do it automatically when changing the scene and restore it in the next one.

    You could store the data either in ORK game variables (global variables can be accessed via ORK.Game.Variables) or simply use Unity's PlayerPrefs. In case the control keeps track of rotation/positioning with some internal variables you might also need to store/restore those values.
    Please consider rating/reviewing my products on the Asset Store (hopefully positively), as that helps tremendously with getting found.
    If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
  • thanks, yeah, i've been tinkering (unsuccessfully so far) with a similar approach to the one you outlined

    i'll keep plugging away
  • ok, after some trial and error, i think i've come up with a viable solution. i'll outline it here in case it's of use to anybody (as i think some other people here use the PhatRobat camera):

    firstly, i have a constantly running event in all my scenes which keeps track of the RPG Camera rotation when not in battle. it stores it in the cunningly named global variable cameraRotation. (there may be better ways, and places, to do this, as it's running all the time, although it only really needs to run just before a battle starts)

    then, in the RPG Camera Start function, i've added the following, which sets a public variable called originRotation, which the RPG Camera system uses to initialise its rotation:
                if (ORK.Game != null)
    {
    Vector3 camRot = ORK.Game.Variables.GetVector3("cameraRotation");
    if (camRot != Vector3.zero)
    {
    originRotation = new Vector2(camRot.y, 0);
    //Debug.Log("RPG CAMERA START originRotation set to: " + originRotation);
    }
    }
    now, when returning from the Arena, the camera shows the same angle it was showing before going into combat

    a couple of things to note:

    firstly, the ORK.Game null check is there because if you bypass the main menu for normal testing purposes then on the first call of the RPG Camera Start function ORK.Game is null, and your console gets spammed with a heap of errors

    secondly, the rotation is stored by Ork as a Vector3, but the RPG Camera originRotation variable is a Vector2, where the first element is equivalent to the y rotation (confused? yeah, me too)


    anyhoo, thanks for the help and suggestions gil
  • You can also check (maybe additionally) if ORK is initiallized (ORK.Initialized) or the player is spawned (ORK.Game.GetPlayer() != null).
    Vector2 and Vector3 can be used without any conversion, V2 just misses the Z-axis of the V3 (i.e. X and Y are the same in both).
    Please consider rating/reviewing my products on the Asset Store (hopefully positively), as that helps tremendously with getting found.
    If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
  • thanks. i've now added that Ork.Initialized check into the function

    as to the Vector2/Vector3 thing, the RPG Camera system, for reasons best known to itself, stores the camera Y rotation angle in the first element of the Vector2 originRotation, not the second, so you can't just do a straight transfer of ork's stored Vector3 rotation, you need to extract the second element of ork's Vector3, and plug it into the first element of the RPG Camera Vector2

    um. i think

    (well, it seems to work anyway)

    ...

    one other thing that i discovered after posting, was that my normal scene change camera angles were now screwed, so i had to do a little bit more jiggering around to get those to work again

    but everything's fine now. and nothing's ever going to go wrong ever again


    not ever...

Sign In or Register to comment.