N
N
nano_e_t_42019-12-04 23:43:52
Game development
nano_e_t_4, 2019-12-04 23:43:52

Why does the corner disappear when creating an object from a prefab?

Hello everyone
I'm creating an object from a prefab. In the prefab, the object has an angle (0, 90, 0 for example). After creation, the object gets an angle that is different from the prefab. Why and how to correct the behavior (so that the angle of the prefab and the angle of the new object match)

WeaponItem currentWeapon = WeaponsInventary.instance.GetCurrentWeapon();
                GameObject shootingPoint = Utils.FindObjectByTag(gameObject, shootingPointTag);
                Debug.Log(currentWeapon.bullet.transform.rotation);
                Debug.Log(currentWeapon.bullet.transform.localRotation);
                GameObject bullet = Instantiate(currentWeapon.bullet,
                shootingPoint.transform.position, Quaternion.identity);
                bullet.transform.localRotation = Quaternion.Euler(currentWeapon.bullet.transform.localRotation.x,
                    currentWeapon.bullet.transform.localRotation.y, currentWeapon.bullet.transform.localRotation.z);

WeaponItem is a ScriptableObject to which the prefab of the bullet is attached with the angle set
, respectively, in the debug, the coordinates do not match the coordinates in the prefab

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
I_GRIN_I, 2019-12-05
@I_GRIN_I

You yourself in the 3rd Instantiate argument pass an empty quaternion. This is the turn.

D
Denis Gaydak, 2019-12-05
@MrMureno

bullet.transform.localEulerAngles =  new Vector3(currentWeapon.bullet.transform.localRotation.x,
                    currentWeapon.bullet.transform.localRotation.y, currentWeapon.bullet.transform.localRotation.z);

I can only suggest trying to assign it like this. not through a quaternion. and equate the local Euler angles to the local Euler angles.
The quaternion simply returns the given rotation in the global space, so to speak) and you shove it into the local rotation.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question