N
N
nano_e_t_42019-11-17 16:09:52
Game development
nano_e_t_4, 2019-11-17 16:09:52

How does object rotation work?

Hello everyone
I'm trying to solve the problem of raising a new weapon by a player (I import 3d objects from a blender). According to the idea, after raising the barrel of the weapon, it should look towards the mouse along the y axis (3d game with the camera setting on top, like in alien shooter). But in the end, the weapon looks a little in the wrong direction. Please tell me how to fix it. The code in which the player picks up a weapon:

Vector3 mPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
        Vector3 pos = mPosition = player.transform.position;

        Quaternion initialRot = weapon.transform.localRotation;
        GameObject prevW = player.GetComponentInChildren<ShootingScript>().gameObject;
        GameObject w = Instantiate(weapon, prevW.transform.position, Quaternion.identity * Quaternion.Euler(0, pos.y, 0));
        w.transform.SetParent(prevW.gameObject.transform.parent);
        w.name = "Gun";
        w.AddComponent<ShootingScript>();
        Destroy(w.GetComponent<WeaponRotationScript>());
        Destroy(prevW);

here
Quaternion initialRot = weapon.transform.localRotation;

the weapon object (this is a processed prefab), zero coordinates in position, rotation, unit scale
ps
and in general, I try to do this:
GameObject w = Instantiate(weapon, prevW.transform.position, Quaternion.identity * Quaternion.Euler(0, 0, 0));

but in the end the Gun object is rotated along one of the axes. Tell me, who knows why it might be so
pss
I just tried to apply the Quaternion.Euler(0, 0, 0) function, without multiplication, the situation does not change, the rotation vector is still different from zero

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question