Scaling object affects its position?
I'm creating a laser for my 2D game. It does not work as it should. The script : 1. spawns laser on position and rotation of the weapon; 2. moves it to the position between target and weapon (constT is a readonly float); 3. sets laser's scale (constS is a readonly float); Spawning works correctly, setting position works correctly, but setting the scale somehow moves and rotates the laser. Experiments I made showed that the script thinks only the scale has changed (I had Debug.Logs that logged laser.localEulerAngles.z, laser.localPosition.y etc. before and after scalling) even though the Inspector shows that position.y and rotation.z are not 0. Setting laser's position and rotation after scalling (for example : laser.transform.localEulerAngles = Vector3.zero, laser.transform.SetPositionAndRotation() and more) had no effect. I couldn't find the solution to my problem on the internet, so I am asking here : Why does the scale affect object's position and rotation, why my current ways to fix it had no effect and how can I fix the problem? The code (laser is a GameObject, distance is the distance between target and weapon) :
laser = Instantiate(prefab, transform); // Spawn laser
laser.transform.localPosition = new Vector3(distance * constT,0,0); // Position
laser.transform.localScale = new Vector3(distance * constS, 2.5f, 1); // This behaves in a weird way
Inspector transform screenshot :
Please, help me in any way.
Your answer
Follow this Question
Related Questions
How to calculate future position of animated object based on root motion animation? 0 Answers
Child always on parent top to get the number of dice 0 Answers
Why does my weapon rotation change after hitting play? 0 Answers
How to make character movement track users head rotation 0 Answers
How to transform a GameObject to an Empty GameObject's position and rotation 1 Answer