Hey all! I’m very new to Unity, and I’m trying to write a script that makes my character’s sword rotate out. My script does work, but only when I’m facing the z-direction.
The following code makes my character’s sword rotate as it should (if I’m facing the z-direction),
However, if I am facing any other direction, my sword’s position does not work as it should, like this:
If anyone can help me with my me with this, that would be much appreciated! (Also, I don’t understand how to make the sword rotate smoothly even after looking up tutorials and the Unity documentation for C#. Currently, it just teleports in place. I’d be very thankful for any help on that too!)
Setting .eulerAngles and / or .localEulerAngles is problematic due to gimbal lock. For small offsets (under 90 degrees) it might work, but beyond that you will get some form of gimbal lock.
You may wish to consider just doing an animation for this type of thing. It’s kinda the way swords are drawn throughout most games.