- Home /
Done Something Wrong, Don't Know What I've Done?
Hi
I've got my asteroid, when i shoot it it should be destroyed and instantiate 4 more in its place. To do that I have created 4 empty game objects around my asteroid to spawn the others. I'm only using the X and Z axis as it is top down so they should spawn at 0 on the Y.
I was trying to make the asteroids bounce of other objects so I added a bouncy physic material. Next thing I know the asteroids instantiate all over the y axis? I froze position on the Y axis in rigidbody and took bouncy off but its still doing it. All spawn points are at 0 on the Y yet the asteroids instantiate off of 0 which they didn't before?
Any ideas what I could have done?
EDIT I've taken the code that deals and may affect with the instantiation issue. Asteroid Controller deals with instantiating.
The spawnUpper and spawnLower etc is looking top down so it differs on the X rather than on the Y. If that makes sense.
public GameObject mAsteroid1;
public Transform spawnUpper;
public Transform spawnLower;
public Transform spawnLeft;
public Transform spawnRight;
void OnTriggerEnter (Collider other)
{
Destroy (other.gameObject);
Destroy (gameObject);
Instantiate(mAsteroid1, spawnUpper.position, transform.rotation);
Instantiate(mAsteroid1, spawnLower.position, transform.rotation);
Instantiate(mAsteroid1, spawnLeft.position, transform.rotation);
Instantiate(mAsteroid1, spawnRight.position, transform.rotation);
}
Asteroid Mover
void Start ()
{
//random rotator
rigidbody.angularVelocity = Random.insideUnitSphere * tumble;
//movement
Vector3 randomDirection = new Vector3(Random.Range(-1, 1), 0.0f, Random.Range(-1, 1));
rigidbody.velocity = randomDirection * speed;
}
edit the discription and add your code in it. we can't answer you without knowing what the code is
Answer by Arcadewiz · Jul 30, 2014 at 09:39 AM
Without code its a bit of a chore to understand whats going on ...
You can try one thing :
In the game view Unselect Maximise on Play.
Then run your scene and when the wrong kinds of object instantiate
Press the pause button.
Select the initialised game objects by selecting them in hierarchy view on the left panel.
Check the properties of the new instantiated game objects and you might be able to trace whats gone wrong.
Then you can also disable renderers selectively is there are too many object.
You can always pause and modify on runtime till the point you discover where you went wrong.
Hope this helps.
I've done what you've suggested, and they seem to be actually spawning above/below the spawn points I've made. Since I put bouncy material on, I've had to freeze the Y position on the rigidbody to keep the first asteroid on 0. When the others instantiate, without freezing the Y they go all over, by freezing the Y they are trapped on the Y axis value they spawned at which isn't 0.
To me it looks like Bouncy screwed things up but I can't see how it has, even if I take Bouncy off its the same result.
Did you remove the "bounce" component or disable it from the source of your instantiation. If it is being instantiated from a prefab in project, you need to modify it there. Your instantiation code needs to be checked.
Just posted the code. I have been removing it from the Collider in the prefab itself. It doesn't seem to make a difference though.
Do your instantiated objects at run-time show "bounce" physics material in their collider ?
Answer by VAN-D00M · Jul 30, 2014 at 12:50 PM
I worked out whats gone wrong. The spawn points seem to be rotation with the asteroid meaning the spawn points are changing regarding the Y axis. Don't know why its doing that as it wasn't before so I've just got to work out how to stop those rotating but still following the asteroid.
[1]: /storage/temp/30057-screen+shot+2014-07-30+at+13.45.01.png
Comment out this in your code and try running:
rigidbody.angularVelocity = Random.insideUnitSphere * tumble;
That does it but it stops my asteroid tumbling about. If I was to fiddle with the parent and child objects something like that could work?
Your answer
![](https://koobas.hobune.stream/wayback/20220613155352im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
NullReferenceException: I think unity bug 3 Answers
Y value wont work? 1 Answer
Ramp shader with outline ? 0 Answers
Problem with OnTriggerEnter() 1 Answer