Search Unity

Objects Forward Vector keeps changing back to the default forward vector when jumping!

Discussion in 'Scripting' started by JanDawid, Aug 29, 2015.

  1. JanDawid

    JanDawid

    Joined:
    Jul 7, 2014
    Posts:
    283
    My code for my character is very complex so I won't bother showing the code itself. My problem is that when my character jumps out of water (specifically) the character just turns to face in the direction of the default Vector3.forward. This doesn't happen when it jumps on land and uses the exact same code to jump.

    My question is, what could cause this? Usually when the forward vector is null or there is some kind of problem, I get a message in the console saying 'Look Rotation Vector is zero' (or something like that) but it's not happening here. I have gone through debugging the code and none of the lines that adjust the transform.forward variable or call a RotateAround() or a LookAt() function are having any affect on this.
    There are 11 uses of transform.forward, each I have checked, so it's definitely not any of those. And I have checked other scripts (2 in total), which has showed that they're not causing this behavior either. It runs the EXACT same code as when you jump off land, only difference is that it says this time that you are no longer in the water (changes one bool).

    What other possible explanations could there be? Any ideas are welcome because I have no idea where else to start looking to fix this issue.
     
  2. georetro

    georetro

    Joined:
    Jan 18, 2013
    Posts:
    218
    Could you post the code as it would be a lot more helpful.
     
    JanDawid likes this.
  3. JanDawid

    JanDawid

    Joined:
    Jul 7, 2014
    Posts:
    283
    It is over 2000 lines and is part of an asset I'm currently selling so I'm afraid I can't.

    I'm mainly asking what could really cause having a forward vector of an object to turn to the default forward vector. Trust me when I say that I've checked all the obvious signs.
     
  4. georetro

    georetro

    Joined:
    Jan 18, 2013
    Posts:
    218
    @Jakeiiii Ahh ok. That's fine. I'm not quite sure when thinking about something like this. I personally would maybe install a breakpoint on the particular line and try to break down what happens to Vector3.Forward at the point of jumping. Do this for both in water and on land.
     
    JanDawid likes this.
  5. JanDawid

    JanDawid

    Joined:
    Jul 7, 2014
    Posts:
    283
    OH I just solved it.
    It was because when the character leaves the water, the transform.up was set to Vector3.up which uses the default forward vector. I don't know why I left that line of code in because it's obsolete as I've been using a different method to change its x-rotation when leaving the water.

    Case closed. Lesson to be learned: Using Vector3.up, right or forward will affect the others.
     
    georetro likes this.