Closed Doh-a closed 11 years ago
Which vehicle are you using - Autonomous or Biped? I expect autonomous, given your mention of _speed, but how can that value be null? It's a float, and value types cannot be null.
Please elaborate.
Sorry about the lack of precision.
Yes it's an autonomous Vehicle (it's for some kind of bugs, so I think this is the best in my case).
You are right _speed is not null, it's at NaN. I cannot explain why.
In the Velocity I put this lines :
Debug.Log("speed : " + _speed);
Debug.Log("forward : " + Transform.forward);
return Transform.forward * _speed;
And I get two kind of outputs. One which is good : speed : 0 forward : (0.0, 0.0, 1.0)
And one which is not : speed : NaN forward : (-0.2, -0.1, 1.0)
Which of course got a :
rigidbody.position assign attempt for 'walkingBug(Clone)' is not valid. Input position is { NaN, NaN, NaN }.
UnityEngine.Rigidbody:MovePosition(Vector3)
TickedVehicle:ApplySteeringForce(Single) (at Assets/AlterfaceProject/scripts/UnitySteer/Behaviors/TickedVehicle.cs:268)
I'm still looking for a good explanation about this. And in particular why some times I've got a speed at 0 and some time at NaN. Unfortunatly I didn't manage to find out. I never change the speed by myself (anyway this is an internal value).
After some others tests.
If I changed the declaration, in order to init the value like that :
float _speed = 0.0f;
I got the same problem which make sens, this is the same thing than float _speed; (http://msdn.microsoft.com/en-us/library/83fhsxwc.aspx)
But if I change the init value to :
float _speed = 0.1f;
I got no error at all.
A final test to be really sure. I changed a little bit the CalculatePositionDelta like this :
protected override Vector3 CalculatePositionDelta(float deltaTime)
{
if(System.Single.IsNaN(_speed))
return new Vector3(0,0,0);
else
return Velocity * deltaTime;
}
Of course I get no error, wich mean the trouble is really that _speed is at NaN. But this is like killing the messenger, it was just a test to be sure.
I'm probably missing a simple thing, but I'm not able to find what.
If you look at the AutonomousVehicle code, you'll see that the only place where _speed is set is on the Speed setter, and the only thing that does is a perform a clamp of the value passed with MaxSpeed. I suggest you add some Debug.LogError in the care of either being a NaN, along with a stacktrace, right about here:
https://github.com/ricardojmendez/UnitySteer/blob/development/Behaviors/AutonomousVehicle.cs#L22
Closing until we get more details.
Hi,
using unitySteer for my project (lots of bugs running in a scene), I had some troubles with this version (used an older one, but I really need this optimized one).
If the speed of the vehicle is null at first, when we calculate the Velocity : return Transform.forward * _speed; (line 34)
we get a NaN;
So I changed the _speed from the initialization in the code (line 14), this is probably not the best solution, and I think I have this error due to a bad usage of your class. But this works for me. Is there a better way to do this ?