Need help in object transfrom changing for no reason ( second time asking cause last time no help.)

So i decided to rebuild a project that i worked on due to big problem which couldent find how to fix , i have the same scripts which was the hardest thing for me , and im allmost going to the same point but I have this 1 problem that stops me from going forward.

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class EndlessPaths : MonoBehaviour {
    public GameObject[] Paths;
    private Transform PlayerTransform;
    private float SpawnZ = -20.0f;//the first tile
    private float PathZ = 60.0f;//space between tiles
    private int MaximumPath = 2;//max paths loaded at a time
    private List<GameObject> OpenedPaths;//list of paths that are loaded , deleting the not seen one(olders);
    private float SafeZone=8.0f;
    private int lastPrefabIndex = 0;
    private void Start () {
        OpenedPaths = new List<GameObject> ();
        PlayerTransform = GameObject.FindGameObjectWithTag ("Player").transform;
        for (int i = 0; i <= MaximumPath; i++)
        {
            if (i < 1)
                SpawnPaths (0);//first 1 paths are free from dying
            else
            SpawnPaths ();//normal paths
        }
    }
  
    // Update is called once per frame
    private void Update () {
        if (PlayerTransform.position.z- SafeZone> (SpawnZ - MaximumPath * PathZ))
        {
            SpawnPaths ();
            DeletePath ();
        }
    }
    private void SpawnPaths(int prefabindex = -1)
    {
        GameObject go;
        if (prefabindex == -1)
            go = Instantiate (Paths [RandomPrefabIndex ()]) as GameObject;//cloning
        else
            go = Instantiate (Paths [prefabindex])as GameObject;
        go.transform.SetParent (transform);
        go.transform.position = Vector3.forward * SpawnZ;
        SpawnZ += PathZ;//spawn tile above then here it add the space between tiles and remaking the gameobject Z spawn .
        OpenedPaths.Add (go);
    }
    private void DeletePath()
    {
        Destroy (OpenedPaths [0]);//delete the clone gameobject of the prefab
        OpenedPaths.RemoveAt(0);//revoming it from the list
    }
    private int RandomPrefabIndex()//randomize the paths
    {
        if (Paths.Length <= 1)
            return 0;
        int randomIndex = lastPrefabIndex;
        while (randomIndex == lastPrefabIndex)
        {
            randomIndex = Random.Range(0,Paths.Length);
        }
        lastPrefabIndex = randomIndex;
        return randomIndex;
    }
}

MPORTENT TO MENTION : im 99% sure its not the scripts , just made it here cause i know some people will think its because of it so i put here to let them see.

This is the script that attached to an EmptyGame object which called PathManager and his job is to spawn tile endlessly ( like tample run ) and delete those behind , simple , worked perfectly on my last project but here for some reason its screwing with the tile transform.Y , Screenshot by Lightshot ass seen in this picture , the tile i have is on -10.8 on Y and X is 0 and Z is -20 (0,-10.8f,-20) transform , the Y is not 0 because the bridge from the assest I downloaded from the store is build that way cause the transfrom cube itself is not on the bridge ground so 0 is actully higher and i want the bridge to be on the ground , so my player can walk on 0 ( make it more comfrobale for me ) , When im buidling the bridge , putting it on those points and putting it in the prefab folder , then putting it in the List on the path manager script it spawn it on (0,0,-20) Which put it higher Screenshot by Lightshot for no reason at all , the same script worked perfectly on my last project and its also working here good expect the Y probelem ( going endleslly and all the other transfro points (x and z) are well placed ) and this is driving me crazy cause there absulutly nothing that should make that go this.

i allredy posted this probebly befor and got no replies nor people watching this , i truly hope someone can help me cause im newbe , also sorry for my bad english , english isnt my mother tangue :slight_smile:

.

Sounds like the bridge’s origin is not within its bounding box (usually center of mass), but 10 units below the bridge geometry itself. I don’t think Unity has a way to correct this offset in the asset itself, without writing up a script to do this, like in an AssetPostprocessor to correct the problem. Ideally, if you can load the model in a 3d modeling program like Blender, you can easily adjust the origin/pivot point of the bridge to be 0, and re-export it. Failing all those options, you’ll just have to make do with setting the positions in your game scripts.

1 Like

thanks :slight_smile: