Greetings unity forum goers, I’m here again with another little issue;
The game I’m working on has a selection of jockeys and animals that are selected by players - on the racetrack, I need the correct animal and jockey to spawn next to each other as children of the “Player1”, 2, 3 etc empty gameobject so they will move at the same time since the script controlling movement is attached to it. At the moment I’m instantiating the objects, but they aren’t spawning in the right places;
Each section of my game has a background brick with everything in front of it. The racetrack is 3 of these background bricks across so the animals have some space to race in. I’ve noticed that relative to the center of the racetrack Player1 is -24 on the x axis, and in my code I’ve only told the animal to instantiate as I thought it would spawn at a 0, 0, 0 relative to the object spawning it. Instead, the animal is spawning at -24 on the world’s co-ordinates. Here’s the code I’m using for the animals;
if (AnimalSelect.player1animal == 1)
{
Instantiate (SpawnAss);
Debug.Log(“the ass has been spawned, apparently…”);
}
In comparison, for the jockey, I wrote this;
if (JockeySelect.player1jockey == 1)
{
Instantiate (SpawnBrown, Vector3(-0.5, 0, 0), Quaternion.identity);
}
Unfortunately, the jockey spawns at -0.5 on the world co-ordinates rather than relative to the Player1 object.
I’ve got to say I’m thoroughly confused - rather than spawning relative to the object that created them, the animals and jockeys are spawning on the world’s co-ordinates. What I need is for them to spawn relative to the object that created them and be a child of that object so they will move with it.
Sorry to bother you with this, but I’ve searched the forums already only finding people with similar problems and no replies to their threads. As for the scripting reference, there’s nothing about how to assign objects when they are instantiated. It’s particularly difficult to look for a solution because I don’t know what commands I’m looking for. I know there are other ways around this, but with 6 jockeys and 6 animals thats rather a lot of code being repeated that isn’t necessary. An example of how to assign the objects would be brilliant, and some clarification how to spawn them in the right place would be very helpful as well.
Thanks in advance, much love from FreakFish.