AlpakaJoe
AlpakaJoe

Reputation: 593

Unity: Instantiated Object gets always the rotation of the spawner Object

I have a zombie. When he dies, he should spawn a shotgun munition package, which the player can collect.

I want the rotation of the shotgunMunition to be 0, 0, 0.

So i used Quaternion.identity, but the munition gets always spawned with the rotation of the zombie.

This is my code:

Instantiate(shotgunMuni, transform.position, Quaternion.identity);

What i tried yet:

Upvotes: 0

Views: 2885

Answers (1)

Jan Soe
Jan Soe

Reputation: 51

If shotgunMuni is a child of a rotated object a rotation of zero will have it rotated to it's parents rotation. In your case it might be a child of zombie and therefore rotated. I can think of three ways to get your ammunition spawned with zero rotation.

  1. Set the global rotation after instantiating your object.

    GameObject shotgunMuniInstance = Instantiate(shotgunMuni, transform.position, Quaternion.identity);
    shotgunMuniInstance.eulerAngles = Vector3.zero; // This is in global space
    
  2. Rotate the child object by the negative rotation of it's parent.

  3. Have a seperate transform as a parent for your ammunition which has zero rotation.

Upvotes: 2

Related Questions