• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by sruthidivakar · Jul 19, 2013 at 06:19 AM · transform.positionwheelcollider

transform.position assign attempt is not valid. input position is {NaN,NaN,NaN} while assign position to a gameobject

Hi,

Here is my code

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

public class car_script : MonoBehaviour {

 public WheelCollider FrontRightWheel;
 public WheelCollider FrontLeftWheel;
 public WheelCollider BackLeftWheel;
 public WheelCollider BackRightWheel;
 
 //-- wheels --
 public GameObject FRWheel;
 public GameObject FLWheel;
 public GameObject BRWheel;
 public GameObject BLWheel;
 
 float EngineTorque = 800;
 float MaxEngineRPM = 3000;
 float MinEngineRPM = 1000;
 private float EngineRPM = 0;
 
 public float[] GearRatio;
 public int CurrentGear = 0;
 
 public  GameObject waypointContainer;
 private List<Transform> waypoints;
 private int currentWaypoint = 0;
 
 private float inputSteer = 0;
 private float inputTorque  = 0;

 Vector3 angle;
 Vector3 last_positionAI1 = new Vector3(0f,0f,0f);

 void Start()
 {
     rigidbody.centerOfMass = new Vector3(0, -0.1f, 0);
     GetWaypoints();
 }
 
 // Update is called once per frame
 void Update () 
 {
     angle = waypoints[currentWaypoint].transform.eulerAngles;
     last_positionAI1 = waypoints[currentWaypoint].transform.position;
     if(FrontLeftWheel.isGrounded || FrontRightWheel.isGrounded || 
     BackLeftWheel.isGrounded || BackRightWheel.isGrounded)
     {
         rigidbody.drag = rigidbody.velocity.magnitude / 250f;
     }
     else
     {
         rigidbody.drag = 20f;
     }
     
     if(city_AI1_collision_detection.AI1_reposition)
     {
         repositioning();
     }
                 
     NavigateTowardsWaypoint();
     EngineRPM = (FrontLeftWheel.rpm + FrontRightWheel.rpm)/2f * GearRatio[CurrentGear];
     ShiftGears();            
     FrontLeftWheel.motorTorque = Mathf.Abs(EngineTorque / GearRatio[CurrentGear] * inputTorque);
     FrontRightWheel.motorTorque = Mathf.Abs(EngineTorque / GearRatio[CurrentGear] * inputTorque);            
     FrontLeftWheel.steerAngle = 10 * inputSteer;
     FrontRightWheel.steerAngle = 10 * inputSteer;
 }
 
 
 void repositioning()
 {
     if (!float.IsNaN(last_positionAI1.x) && 
         !float.IsNaN(last_positionAI1.y) && !float.IsNaN(last_positionAI1.z))
     {
         print (last_positionAI1);
         transform.position = new Vector3(last_positionAI1.x,last_positionAI1.y,last_positionAI1.z);
     }
     city_AI1_collision_detection.AI1_reposition = false;
 }
 
 void GetWaypoints () 
 { 
     Transform[] potentialWaypoints = waypointContainer.GetComponentsInChildren<Transform>();
     waypoints = new List<Transform>();
     foreach ( Transform potentialWaypoint in potentialWaypoints ) 
     {
         if ( potentialWaypoint != waypointContainer.transform )
          waypoints.Add(potentialWaypoint);
     }
     
 }
 
 void ShiftGears() 
 {
     int AppropriateGear=0;
     if ( EngineRPM >= MaxEngineRPM ) 
     {
         AppropriateGear = CurrentGear;
         for ( int i = 0; i < GearRatio.Length; i ++ ) 
         {
             if ( FrontLeftWheel.rpm * GearRatio[i] < MaxEngineRPM ) 
              {
                 AppropriateGear = i;
                 break;
             }
         }
         CurrentGear = AppropriateGear;
     }
     
     if ( EngineRPM <= MinEngineRPM ) 
     {    
         for(int j = GearRatio.Length-1; j >= 0; j --)
         {
             if ( FrontLeftWheel.rpm * GearRatio[j] > MinEngineRPM ) 
             {
                 AppropriateGear = j;
                 break;
             }
         }
         CurrentGear = AppropriateGear;
     }   
 }
 
 void NavigateTowardsWaypoint()
 {
     Vector3 RelativeWaypointPosition = transform.InverseTransformPoint( new Vector3( 
                                             waypoints[currentWaypoint].position.x, 
                                             transform.position.y, 
                                             waypoints[currentWaypoint].position.z ) );
     float magnitude = Vector3.Distance(transform.position,waypoints[currentWaypoint].position);

     inputSteer = RelativeWaypointPosition.x / RelativeWaypointPosition.magnitude;
     if ( Mathf.Abs( inputSteer ) < 0.5 )
     {
         inputTorque = RelativeWaypointPosition.z / RelativeWaypointPosition.magnitude - Mathf.Abs( inputSteer );
     }
     else
         inputTorque = 0.0f;

     if ( magnitude < 20 ) 
     {
         currentWaypoint ++;
         if ( currentWaypoint >= waypoints.Count )
             currentWaypoint = 0;
     }
 }

}

While printing the value 'last_positionAI1' i will get the correct answer. But when I assign it to the gameobject it will show 'transform.position assign attempt is not valid. input position is {NaN,NaN,NaN} while assign position to a gameobject'.

So you have any idea how I could fix this?

Thx

Comment
Add comment · Show 6
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image perchik · Jul 19, 2013 at 06:02 PM 1
Share

So to clarify, last_positionAI1 at line 71 prints fine but then line 72 throws an error?

avatar image Benproductions1 · Jul 22, 2013 at 12:25 AM 0
Share

.position = Vector3(pos.x, pos.y, pos.z) is completely irellevant...

Just go .position = pos

avatar image sruthidivakar · Jul 29, 2013 at 04:09 AM 0
Share

'last_positionAI1' is the position of the last waypoint passed by the car.

avatar image Benproductions1 · Jul 29, 2013 at 04:14 AM 0
Share

We know that!, but does it print fine or not?

avatar image sruthidivakar · Jul 29, 2013 at 05:20 AM 0
Share

it prints fine.. I tried .position = pos. But the error is still there..

Show more comments

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

17 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Transform.position affected by children 1 Answer

RayCastHit 2 Answers

Player position with Joystick and Head Tracker 1 Answer

Delaying a dynamic Variable(transform.position for Ex.) 2 Answers

Problem with rotation and groundchek _ 2D - C# 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges