Forum rules - please read before posting.

Lock or unlock Third person Camera's Spin rotation at runtime.

edited August 2016 in Technical Q&A
Hi, everyone, I don't know if I'm being silly, but I can't get this to work. I basically want to change the spin rotation type depending on if the player is dragging on the screen or not (excluding when the pointer is over himself). Problem is, no matter how I do it the camera doesn't react at all... I've tried attaching it to a field in the inspector, tried searching it by script/name, but nothing, so I'm wondering if I'm casting it wrong or if there's something else I need to do to get to the camera... also, in case it's important, I have 3 cameras, but only one is a third person camera. Also I'm using Mouse and Keyboard/direct control. And, Here is a basic example of the code (but I'm actually using raycasts, and other stuff):

using AC;
public GameCameraThirdPerson CloseUpCam;
void Awake()
{
CloseUpCam = FindObjectOfType<GameCameraThirdPerson>();
}
void OnMouseDrag()
{

    if (CloseUpCam.spinLock != RotationLock.Locked) 
// I've tried without the conditionals but same, also I want them because th code will be in a loop
    {
        CloseUpCam.spinLock = RotationLock.Locked;
    }
}
void OnMouseUp()
{
    if (CloseUpCam.spinLock != RotationLock.Limited)
    {
        CloseUpCam.spinLock = RotationLock.Limited;
    }
}

Anyways, has anyone had to do this before who can give me an idea? As always, any advice will be greatly appreciated.

Comments

  • Ought to work, at least so far as accessing the camera goes.  Any error messages in the console?

    Try writing a simple OnGUI function to display buttons that manually change the spinLock variable, to test that they actually respond properly.  Assuming they do, the problem will then be narrowed down to the OnMouseDrag/Up functions not getting called.
  • edited August 2016
    I didn't get any red warnings but I've been ignoring yellow ones, so I'll double check. Updating to Unity 5.4 got me like a 100 yellow warnings in my assets... :-<). 

    Still, the funny thing is, I'm using the same methods and coroutines to detect, start and stop swiping/rubbing and that's working just fine. I've basically put the code to change the camera's state right in the middle of the same processes, yet nothing happens :(|). But I'll have to check if I'm missing something (maybe a yellow warning) or hopefully something silly.
  • Alright, it was something silly... buried in my scene there was another Third person camera that was getting affected instead... Still, the method I posted above doesn't really do me any good. I wasn't aware that OnMouseDrag() only fires if you drag over the object the script is attached to, or at least it seems that way?  The code only fires when I click the character, not everything else (which is the opposite of what I want, because the character is a pet you can "pet" when you click it, so camera rotation there would get in the way)... 

    Well, I guess I'll have to calculate this with a separate raycast and inputs changes?... Anyway, thank's for the advice, it helped me look back a find the problem.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.