How should I change the script so I will be able to change the transform height while the game is running and the transform is following?

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.UI;

{
public Transform targetToFollow;
public Transform missionTarget;
public Text textDistance;
public Text textSpeed;
public float lookAtRotationSpeed;
public float moveSpeed;
public float speedBoost = 0.5f;

void Start()
{

}

// Update is called once per frame
void FixedUpdate()
{
Vector3 lTargetDir = targetToFollow.position - transform.position;
lTargetDir.y = 0.0f;
transform.rotation = Quaternion.RotateTowards(transform.rotation,
Quaternion.LookRotation(lTargetDir), Time.time * lookAtRotationSpeed);

float ms = moveSpeed;
var distance = Vector3.Distance(transform.position, targetToFollow.position);
// Compute a position no further than followRadius away from our target.
Vector3 stopPoint = targetToFollow.position + fromTarget;

// Compute a speed that's faster when far away and slower when close.

ms = moveSpeed + speedBlend * speedBoost;

// Move as far as we can at our speed ms to reach the stopPoint, without overshooting.
transform.position = Vector3.MoveTowards(transform.position, stopPoint, Time.deltaTime * ms);
}

private void Mission()
{

}
}


I mean the transform of the gameObject the script is on. I want to keep the y position up all the way or at least make it finish moving on the ground or above the ground depending on my settings.

Now the transform the script is attached to the name is NAVI. NAVI is by default position Y set to 5.94 :

Then the game start NAVI is moving to the target the kid_from_space in this case. Kid_from_space position is at 0,0,0 when the NAVI getting close to the target NAVI position Y is 0 and the result is :

Therefore the NAVI is not on the ground and I also can't change it's Y position up or down. The NAVI is stuck at the Y 0 position. I want to be able to change the Y position up/down, for example if before the game is running I'm setting the Y position of NAVI to 5.94 or 6 or 21 I want the NAVI to stay at this position on the Y and not move down to 0.

• I don't understand this question. You are asking about "the" transform, but there are at least 3 transforms here: the transform of the gameObject this script is on, the targetToFollow and the missionTarget (although the latter seems unused). Which transform do you change, what do you expect that to do and what happens instead? Also, what do you mean with "height"? A transform has no "height". It only has a position and a scale. And which axis is "height" in your game? Usually "up" is y, but when your game doesn't use gravity, then "up" can be whatever you want. – Philipp Dec 22 '20 at 12:15
• It sounds like they're trying to change the y-coordinate elevation of an object. They have a character whose transform origin is in their center. Then they have this script, that positions that origin on the same y plane as their target. I think they want to lift the character up to sit above the target's y plane (and didn't try adding their desired elevation to stopPoint.y for some reason?) – DMGregory Dec 22 '20 at 12:55
• @Philipp You right I mean the transform of the gameObject this script is on. Height I mean the y position up. I will edit my question with a screenshot of what is happening and what I want to do. – Shamen Raze Dec 22 '20 at 17:31
• @DMGregory You right too. I edited my question with two screenshots and explain of what I mean and what I'm trying to do. – Shamen Raze Dec 22 '20 at 17:40

lTargetDir.y = 0.0f;

lTargetDir.y += transform.position.y;