SmoothFollow2D.js to SmoothFollow2D.cs is giving me a no render ship?

I have done this code in C sharp:


using UnityEngine;
using System.Collections;

public class SmoothFollow2 : MonoBehaviour
{
public Transform target;
public float smoothTime = 0.5F;
public static Vector2 yVelocity;
private float newPositiony;
private float newPositionx;
private Transform thisTransform;

void Start()
{
//thisTransform = transform;
}

void Update() {
newPositiony = Mathf.SmoothDamp(thisTransform.position.y, target.position.y, ref yVelocity.y, smoothTime);
newPositionx = Mathf.SmoothDamp(thisTransform.position.x, target.position.x, ref yVelocity.x, smoothTime);

if (newPositiony > thisTransform.position.y)
{
HeroAnimate.Heroindex = 2;
}

if (newPositiony < thisTransform.position.y)
{
HeroAnimate.Heroindex = 1;
}

transform.position = new Vector3(newPositionx, newPositiony, 0);
// I am getting erros here and my ship sometimes has no renderer enabled at the scene start…WHY?

}
}


the original SmoothFollow2D.js in java was:


var target : Transform;
var smoothTime = 0.3;
private var thisTransform : Transform;
private var velocity : Vector2;

function Start()
{
thisTransform = transform;
}

function Update()
{
thisTransform.position.x = Mathf.SmoothDamp( thisTransform.position.x,
target.position.x, velocity.x, smoothTime);
thisTransform.position.y = Mathf.SmoothDamp( thisTransform.position.y,
target.position.y, velocity.y, smoothTime);
}


I have an invisible sphere that get the touches and my ship just follow it, giving me a moving gravity effect. So…Could someone experienced with changing Java to C sharp give a hand here my developer friends. :expressionless:

I found this line of error:

transform.position assign attempt for ‘Player’ is not valid. Input position is { NaN, 0.000000, 0.000000 }.
UnityEngine.Transform:set_position(Vector3)
SmoothFollow2:Update() (at Assets/Scripts/SmoothFollow2.cs:40)

on the line of code:

transform.position = new Vector3(newPositionx, newPositiony, 0);

Any hints here?

Eh, why did you comment out the line thisTransform = transform?

Sorry my code originally was like this:


using UnityEngine;
using System.Collections;

public class SmoothFollow2 : MonoBehaviour
{
public Transform target;
public float smoothTime = 0.5F;
public static Vector2 yVelocity;
private float newPositiony;
private float newPositionx;
private Transform thisTransform;

void Update() {
newPositiony = Mathf.SmoothDamp(transform.position.y, target.position.y, ref yVelocity.y, smoothTime);
newPositionx = Mathf.SmoothDamp(transform.position.x, target.position.x, ref yVelocity.x, smoothTime);

if (newPositiony > transform.position.y)
{
HeroAnimate.Heroindex = 2;
}

if (newPositiony < transform.position.y)
{
HeroAnimate.Heroindex = 1;
}

transform.position = new Vector3(newPositionx, newPositiony, 0.0f);

}
}


this is my original code in C sharp from the Java version!
I was trying to change things so I posted a modified code.
I am getting the error:

transform.position assign attempt for ‘Player’ is not valid. Input position is { NaN, 0.000000, 0.000000 }.
UnityEngine.Transform:set_position(Vector3)
SmoothFollow2:Update() (at Assets/Scripts/SmoothFollow2.cs:40)

on the line of code:

transform.position = new Vector3(newPositionx, newPositiony, 0);

And when it happens on my iphone my ship renderer is disabled but it´s stil there…this is really getting into my nerves because I can´t see the error in here.I know it´s telling me that this → { NaN, 0.000000, 0.000000 } is a wrong coordinate, but why am I getting an error like this?
I read a post telling that this is an error not fixed by the engine? Is this true? I´ll never be able to launch a game that the renderer keeps messing around all the time. Any hints here?