-1

So i made a little game where i want to make a cube jump from a point to another by clicking on point's colliders with a specific tag named "RichPoint"... I have this code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerMovement : MonoBehaviour {

    public float jumpMaxDistance;
    public float jumpSpeed;
    private float distance;

    private bool firstFrame = false;
    private Vector3 richPoint;
    public GameObject player;
    private Animation jump;
    private float pBTime;

    void Start () {
        richPoint = transform.position;
        jump = player.GetComponent<Animation> ();

    }
    // Update is called once per frame
    void Update (){
        //Moves the player to the next richPoint.
        if (firstFrame == true){
            if (transform.position != richPoint) {
                transform.position = Vector3.MoveTowards (transform.position, richPoint, Time.deltaTime * jumpSpeed);


            }//executes if the left click is pressed.
        }
        if (Input.GetMouseButtonDown (0)) {

            RaycastHit hit;

            //Get Ray from mouse position.
            Ray rayCast = Camera.main.ScreenPointToRay (Input.mousePosition);

            //Raycast and check if any object is hit.
            if (Physics.Raycast (rayCast, out hit, jumpMaxDistance)) 
                {
                //Raycast and check if any object is hit.
                if (hit.collider.CompareTag ("RichPoint"))
                {
                    richPoint = hit.collider.transform.position;

                    //This finds the distance between the player and richPoint.
                    distance = Vector3.Distance(transform.position,richPoint);
                    pBTime = distance / pBTime;

                    //This plays the Animation depending on tha distance between transform.position and richPoint.
                    jump ["PlayerJump"].time = pBTime;
                    jump.Play ();

                    firstFrame = true;
                }
            }
        }
    }
}

Now...if i run the game and try to click on colliders i get this errors... ------------------------------------------------------------------------enter image description here

Why? what am i doing wrong,what should i do to fix it?

Dinu Adrian
  • 129
  • 2
  • 13
  • https://forum.unity3d.com/threads/unity-5-3-1f1-particle-system-errors-invalid-aabb-result-isfinite-d.374926/ – Fredrik Schön Mar 20 '17 at 13:02
  • 1
    Please copy and paste the actual text of the error/stacktrace into your question. It'll make others who search for that error able to find this question and its answer. – Harris Mar 20 '17 at 13:07

1 Answers1

2

It seems that pBTime is always zero. So pBTime = distance / pBTime; makes pBTime become float.Infinity. See this for more detial.

This float.Infinity will cause all kinds of error like what you have ran into.

Community
  • 1
  • 1
zwcloud
  • 4,546
  • 3
  • 40
  • 69