Search Unity

Big Camera Bug, pleasee help i need to keep the work up XD

Discussion in '2D' started by Helladah, Aug 22, 2019.

  1. Helladah

    Helladah

    Joined:
    May 5, 2018
    Posts:
    254
    I was trying some spawn scripts an suddenly the game crushed, i stopped it but now its all gray, and the console stills its sendin this:

    transform.position assign attempt for 'SceneCamera' is not valid. Input position is { -124.306213, -5.406476, NaN }.
    UnityEngine.GUIUtility:processEvent(Int32, IntPtr)

    and i dont know what to do, anyone can help me buddies? :(
     
  2. Helladah

    Helladah

    Joined:
    May 5, 2018
    Posts:
    254
    im having other screen reports like:

    transform.position assign attempt for 'rastroCa(Clone)' is not valid. Input position is { -4.717705, 2.338927, Infinity }.
    UnityEngine.Transform:Translate(Single, Single, Single)
    Salpicadura:Update() (atSomeScript.cs:76)

    or

    Assertion failed: Invalid worldAABB. Object is too large or too far away from the origin.


    its a game object that moves alogn the scene spawning other gameObjects, what does it means? why it just dosent spawn right?
     
  3. MisterSkitz

    MisterSkitz

    Joined:
    Sep 2, 2015
    Posts:
    833
    I haven't laughed at an error in a long time! lol
     
  4. Helladah

    Helladah

    Joined:
    May 5, 2018
    Posts:
    254
    its an emoticon one
     
  5. MisterSkitz

    MisterSkitz

    Joined:
    Sep 2, 2015
    Posts:
    833
    I'll entertain this. post some code so I can see exactly why you're spawning Z-axis separate from your intended transform. Two codes must be running simultaneously. However, one is reading Vector2 and the other Vector3. However, I have nothing to base this theory on. The only other thing I can think of is that the script you have on the player is conflicting with that of the camera. Either way, you need some code or there's no real help for you.
     
    Helladah likes this.
  6. Helladah

    Helladah

    Joined:
    May 5, 2018
    Posts:
    254
    well you seems to be right, cause the gameobject that is moving its rotating along his z axis, and the spamer its atached to him, moving along the way but rotating within, thats what i guess cause my spam code its basic and shouldnt have any problem

    Code (CSharp):
    1. public float coolDown = 3f;
    2.     public float countDown;
    3.  
    4.     public GameObject salpi;
    5.  
    6.     // Use this for initialization
    7.     void Start () {
    8.  
    9.         countDown = coolDown;
    10.        
    11.     }
    12.    
    13.     // Update is called once per frame
    14.     void Update () {
    15.  
    16.         countDown -= Time.deltaTime;
    17.         if (countDown <= Time.deltaTime)
    18.         {
    19.             Instantiate(salpi, transform.position, transform.rotation);
    20.             countDown = coolDown;
    21.         }
    22.  
    23.     }
     
  7. MisterSkitz

    MisterSkitz

    Joined:
    Sep 2, 2015
    Posts:
    833
    It seems that transform.rotate seems to be the problem from what I can tell. The camera is trying to match that rotation and it's causing an error. What I THINK I should suggest is to create an empty game object and call it something like "PlayerHolder". Make the player a child of this empty. Then make the camera a child(NOT A CHILD OF THE PLAYER BUT OF THE EMPTY YOU CREATED). Finally, put the script you posted on the PlayerHolder you just created. Either SerializeField or make public variables to store your player and camera separate.

    Now you should be able to rotate the player without compromising the camera. If it's still screwing with the camera's Z-Axis, then you want the camera to focus on the Empty object rather than the player's. That way the transform.rotation isn't interfering.

    I'm really not positive about this but MAYBE try this also:

    Code (CSharp):
    1. private float rotationCounter = 0.0f;
    2.  
    3. Instantiate(salpi, transform.position, Quaternion.Slurp(salpi.transform.postion, -salpi.transform.position, rotationCounter);
    4. rotationCounter += Time.deltaTime;
    I've never tested this so not sure if it'll help. Just thought it might be cool to try. Very experimental! Lemme know how it does! :)
     
    Last edited: Aug 26, 2019
  8. Helladah

    Helladah

    Joined:
    May 5, 2018
    Posts:
    254
    yeah i got you, i always have a separate GameObject for the rotation in every prefab, the think its that npc its rotating among his own z axis, cause it seemed to cause conflict with the movement script, so since i noticed, i do that way, and the spamer its a children object of that prefab that under certains conditions get active or deactive, anyway thanks, i really dont think that i could use unlees that i made the spamer unchildren of the prefab, cause the prefab itself has a rotation children that rotate the whole thing, but ill try to use it as soon as i can!
     
    Last edited: Sep 1, 2019
  9. MisterSkitz

    MisterSkitz

    Joined:
    Sep 2, 2015
    Posts:
    833
    When you create an empty game object to store your other game objects in, be sure to reset the transform. I've discovered that your stored objects will teleport to the parents transform otherwise. If resetting your empty object transform doesn't work, then try copying the player object's transform and paste these values to the empty. The main focus should be getting all of your objects aligned at the same point in world space.
     
    bloodwolftico and Helladah like this.
  10. bloodwolftico

    bloodwolftico

    Joined:
    Nov 13, 2017
    Posts:
    100
    Yeah this is good advice. If you move your game objects under a parent, the new child objects keep their position in the world but their new transform is relative to the parent now, so best way to move the parent and not lose track of the children is to set them to 0,0,0 and them align them accordingly.
     
    Last edited: Sep 3, 2019
    Helladah likes this.
  11. Helladah

    Helladah

    Joined:
    May 5, 2018
    Posts:
    254
    that makes a lot of sense, thanks buddies for the help!!
     
    bloodwolftico likes this.
  12. bloodwolftico

    bloodwolftico

    Joined:
    Nov 13, 2017
    Posts:
    100
    I made a mistake, I meant move objects under a parent, as a child.... edited it. But I think you understood me :).
     
    Helladah likes this.
  13. MisterSkitz

    MisterSkitz

    Joined:
    Sep 2, 2015
    Posts:
    833
    I guess I forgot about this post and said the same thing in the other thread. My bad lol
     
  14. Helladah

    Helladah

    Joined:
    May 5, 2018
    Posts:
    254

    i cannot make the camera children of the gameObject cause the game is meant to suport more than one of these npc, or can i¿
     
  15. bart_the_13th

    bart_the_13th

    Joined:
    Jan 16, 2012
    Posts:
    498
    You shouldnt have a NaN as position,check your script if you have some zero divide.
     
    Last edited: Sep 4, 2019
    Helladah likes this.
  16. bloodwolftico

    bloodwolftico

    Joined:
    Nov 13, 2017
    Posts:
    100
    Ugh, I have seen NaN under my canvas items in the past, and it basically "nulls out" any position I have for elements under it, really annoying. I've come to realize if I have UI items inside a prefab, when certain changes are overriden, all my UI items are changed to a NaN position, rotation and scale, and I need to go into Debug mode, change everything back to 0, then back to its original position (really, really tedious).

    I think I know how to reproduce this (the NaN position bug): you have UI items on an prefab, you move this prefab or turn on/off any of the canvases, then do "Override All" under the prefab. Ever since I stopped doing that, my UI elements are no longer at (NaN, NaN, NaN), and now I just do individual overrides on it.
     
    MisterSkitz and Helladah like this.
  17. MisterSkitz

    MisterSkitz

    Joined:
    Sep 2, 2015
    Posts:
    833
    You can make the camera a child of your game object. You'd probably need to set it up to where it triggers on when needed and the other camera off. As far as doing this on NPC, I dunno how efficient that would actually be though.
     
    Helladah likes this.
  18. Helladah

    Helladah

    Joined:
    May 5, 2018
    Posts:
    254
    yeah, besides i dont quite understand the sense of making a camera children of an npc and how conects with the spamer script XDD this thing its going crazy
     
    MisterSkitz likes this.
  19. Helladah

    Helladah

    Joined:
    May 5, 2018
    Posts:
    254
    ok i have debugged the problem, was at the spamed object, within hte movement script a tached to it, it was

    transform.Translate(x * Time.deltaTime, y * Time.deltaTime, transform.position.z);


    instead of

    transform.Translate(x * Time.deltaTime, y * Time.deltaTime, 0);


    lol what a mistake XDD
     
    MisterSkitz and bloodwolftico like this.
  20. MisterSkitz

    MisterSkitz

    Joined:
    Sep 2, 2015
    Posts:
    833
    You'll discover that often errors are little small mistakes like this. Annoying but always a relief to fix it! :p
     
    Helladah likes this.