Answer the question
In order to leave comments, you need to log in
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);
Quaternion initialRot = weapon.transform.localRotation;
GameObject w = Instantiate(weapon, prevW.transform.position, Quaternion.identity * Quaternion.Euler(0, 0, 0));
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question