1

This is my code of the camera:

using UnityEngine;

public class followcamara : MonoBehaviour {

    // Update is called once per frame
    public Transform player;
    public Vector3 offset;
    void Update ()    
    {
        //debug.log(player.position); imprime la posicion del jugador.
        //  transform.position = player.position; // si solo dejamos esta porcion de codigo, 
        //la camara se pusiera en el jugador en 1ra persona, pero como la camara en este juegos la queremos en 3ra 
        //persona, le agregaremos lo siguiente.

        transform.position = player.position + offset;// asi la camara se centra y se modifica a las coordenadas 
        //que le pongamos.

    }
}

These are the values of offset that i put on the inspector: 0.1,2,-5

I get a lot of error, but these are the first three:

enter image description here

These happens when I'm playing in the edge of a road at an certain rotation, something like these, but in the edge of the road. So when it happens y just disappear, and y give me a lot of errors. How can i fix these? I am new on unity.

enter image description here

the player transform coordinates change the values to na,na,na

enter image description here

the code of the movement is

using UnityEngine;

public class playermovement : MonoBehaviour {

    public Rigidbody rb;
    public float fowardforce = 2000f;
    public float sidewaysforce = 500f;
    private bool isdeath = false;

    // Update is called once per frame
    void FixedUpdate ()
        //esta parte de aqui se utiliza para generar una accion a (frames*segundo), 
        //entonces si tu computadora e srapida los Frames seran mayores, por eso agregamos el time.deltatime.
        //que es la cantidad de segundos que la computadora genero el ultimo frame, eje: si la funcion update,
        //ejecuta un frame 10 veces por vez, el time.deltatime va a ser 0.1, si es 20 por segundo su valor ahora es 0.5,
        //este forze hace que las fisicas se ejecuten al mismo tiempo en cada computador estimadamente, sin importar,
        //su capacidad.    
    {
        rb.AddForce(0, 0, fowardforce * Time.deltaTime);
        //input.getkey("tecla") se utiliza para analizar el teclado y ver que tecla se esta pulsando
        if(Input.GetKey("right"))
        {
            rb.AddForce(sidewaysforce * Time.deltaTime, 0, 0,ForceMode.VelocityChange); //x,y,z,cuarto parametro modo fuerza, leelos los diferentes.
        }

        if(Input.GetKey("left"))
        {
            rb.AddForce(-sidewaysforce * Time.deltaTime, 0, 0,ForceMode.VelocityChange);
        }

        if (Input.GetKey("up"))
        {
            rb.AddForce(0, 25, 0);
        }

        if(rb.position.y < -1f)
        {
            // FindObjectOfType<gameManager>().end_game();
            // FindObjectOfType<gameManager>().EndGameModoInfinito();
            death();
            FindObjectOfType<score>().OnDeath();

        }

        if (Input.GetMouseButton(0)) //lee cualquier pulso sin importar la posicion, sirve para mouse y pantallas touch
        {
            if (Input.mousePosition.x > Screen.width / 2) // si la posicion del mouse esta en el eje x, es decir a la derecha
            {
                rb.AddForce(sidewaysforce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
            }

            else
            {
                rb.AddForce(-sidewaysforce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
            }
            //obviamente esta a la izquierda si no es asi
        }    
    }
}
3
  • These images are screenshots of text. You should put the text in here. Read meta.stackoverflow.com/questions/285551/…
    – Nic3500
    Mar 6, 2018 at 1:29
  • sorry these is my first time asking in stackoverflow, is now better?, ive been looking for the answer like a month, reading a lot of post and testing, and nothing has work Mar 6, 2018 at 2:13
  • Welcome to Stackoverflow. I have fixed some issues of your question. Please have a look at stackoverflow.com/help/how-to-ask.
    – zwcloud
    Mar 6, 2018 at 4:47

2 Answers 2

0

I would examine the first exception you've got (Invalid worldAABB: object is too large or too far away...). This is usually raised when an object is too far away from the center of the scene, generally at 5000+ units on a certain axis. This leads to an approximation to Infinity, which is a NaN. Can you check the position of the player and see if you're into such a situation? If my thoughts are correct, you are adding an offset (finite) to a NaN, obtaining...a resulting NaN.

EDIT: Seems that your code is the same as here. Have you tried the same advice, so scaling the Z component of the ground?

3
  • the position of the player when the error occurs is nan,nan,nan, the game is an edless runner that start in 0, y go to z(+). it hapens when the cube rotates, in the edge of the road, and disappear Mar 6, 2018 at 16:47
  • in the testing it happens in any location of z, if the cube is the corner and at the same time rotate aat an certain angle like the photo, only if does two condittion happens at the same time, the nan error apears in the transform of the player Mar 6, 2018 at 16:52
  • @dariotejada: I have edited my answer. Hope this could help.
    – Andrea
    Mar 7, 2018 at 9:03
0

I had the error of Input.mousePosition is { Nan, Nan, Nan} some minutes ago. The cause of the problem was that before assingning the mousePosition to other gameObject I am snaping the position of the mouse to a grid of variable size by dividing it and rounding the original position. In a recent change sometimes that size is set to zero, wich leads to "divide by zero" errors.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.