Question by
tiagoorlando · May 19, 2018 at 06:28 PM ·
transform.positiongameobjectscoordinatesinstantiationracing game
GameObject spawning at several Y distance below my spawn point
I'm building a racing game where start of a race I want to Load() a prefab car and Instantiate() it at the position and rotation of a empty GameObject as spawnPoint reference. No errors or warnings occur, but during runtime, the object(car) aways is instantiated several Y coordinates **below** the desired position (the spawn point reference that I have created), so I aways have to move the spawn point several Y units up so the car doesn't falls into the void.
where I want the car to be spawned.
where it acttually gets spawned.
void Awake () {
// this int is setted at the Track/Car selection UI
CarImport = CarSelector.CarType;
SpawnPosition = GameObject.Find("CarSpawnPoint");
if (CarImport == 1)
{
WheelDrive.driveType = DriveType.FrontWheelDrive;
WheelDrive.maxTorque = 780f;
WheelDrive.m_Topspeed = 189f;
//Loading and instantiating...
var car = Resources.Load("Prefabs/Cars/car Root_001");
CarLoaded = car as GameObject;
Instantiate(CarLoaded, SpawnPosition.transform.position, SpawnPosition.transform.rotation);
}
}
This is a simple load and instantiate code that i wrote for loading different cars on the scene/track.
where-the-car-is-spawned.png
(297.5 kB)
Comment