Quantcast
Channel: Questions in topic: "error"
Viewing all articles
Browse latest Browse all 7934

How to solve error transform.position assign attempt for 'Car' is not valid. Input position is { NaN, NaN, NaN }.

$
0
0
In my game i have a car following a waypoint system, everyting seems to work perfectly but after a random amount of time my AI car stops moving and gives me the error transform.position assign attempt for 'Car' is not valid. Input position is { NaN, NaN, NaN }. This is the code i am using. Any help in solving my problem would be much appreciated. var path : Array; var pathGroup : Transform; var maxSteer : float = 15.0; var wheelFL : WheelCollider; var wheelFR : WheelCollider; var wheelRL : WheelCollider; var wheelRR : WheelCollider; var currentPathObj : int; var direction : float; var distancefrompath :float = 5.0; var maxTorque : float = 50.0; var currentSpeed : float; var topSpeed : float = 50.0; var decellerationSpeed : float = 10.0; var steerVector : Vector3; function Start() { rigidbody.centerOfMass.y = -3.5; GetPath(); } function GetPath() { var path_objs : Array = pathGroup.GetComponentsInChildren(Transform); path = new Array(); for (var path_obj : Transform in path_objs) { if(path_obj != pathGroup) { path[path.length] = path_obj; } } Debug.Log(path.length); } function Update() { GetSteer(); Move(); } function GetSteer() { steerVector = transform.InverseTransformPoint(Vector3(path[currentPathObj].position.x,transform.position.y,transform.position.z)); var newSteer : float = maxSteer * (steerVector.x / steerVector.magnitude); direction = steerVector.x / steerVector.magnitude; wheelFL.steerAngle = newSteer; wheelFR.steerAngle = newSteer; if (steerVector.magnitude <= distancefrompath) { currentPathObj++; if (currentPathObj >= path.length) { currentPathObj = 0; } } } function Move() { currentSpeed = 2*(22/7)*wheelRL.radius*wheelRL.rpm* 60/1000; currentSpeed = Mathf.Round(currentSpeed); if(currentSpeed <= topSpeed) { wheelRL.motorTorque = maxTorque; wheelRR.motorTorque = maxTorque; wheelRL.brakeTorque = 0; wheelRR.brakeTorque = 0; } else { wheelRL.motorTorque = 0; wheelRR.motorTorque = 0; wheelRL.brakeTorque = decellerationSpeed; wheelRR.brakeTorque = decellerationSpeed; } }

Viewing all articles
Browse latest Browse all 7934

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>