#Local - Global Transform Directional Crisis

1 messages Β· Page 1 of 1 (latest)

hushed kettle
#

no clue whats going on. same level under the 0,0,0 rotated container.. yet the same component rotates differently (appears to be local vs global) ❔

haughty crystal
#

Might wanna modify the mesh so that it rotates around X axis, not Z axis

hushed kettle
#

the script is only working per-chance. on these objects and its annoying

haughty crystal
#

Eulers are applied in a certain order, IIRC it is Z -> X -> Y

#

X might work better

hushed kettle
#

i tested the script on a gameobject thats not in the same hierarchy.. and it works fine..

#

with all axis' soo i dont think its the script

hushed kettle
haughty crystal
#

You haven't shown any code yet πŸ€”

hushed kettle
#

not sure why i didnt think of doing that.. i was going to completely delete the two switches.. and import them in as a seperate fbx

#

and then position within the scene

hushed kettle
#
  public float speed = 5f;
  [SerializeField] private bool isOn = false;

  public float min = -45f; // off
  public float max = 45f;  // on

  private void Start()
  {
      float startRotation = isOn ? max : min;
      transform.localRotation = Quaternion.Euler(0f,0f,startRotation);
  }

  private void Update()
  {
      float targetRotation = isOn ? max : min;

      float currentRotation = transform.localEulerAngles.z;
      if(currentRotation > 180f)
          currentRotation -= 360f;

      float newRotation = Mathf.MoveTowards(currentRotation,targetRotation,speed * Time.deltaTime);

      transform.localRotation = Quaternion.Euler(0f,0f,newRotation);
  }```
#

its simplified more than it once was..

#

b/c i was trying to figure out wtf was going on.. if it was the script or the object

#

yea, thats what happened.. i had to keep orientating this switch handle until i got lucky

#

aligning it to the X axis and applying looks fine in blender.. but the import rotates it incorrectly and i need to adjust it.. after that the transform is blown

haughty crystal
#

Gimbal lock weirdness because your mesh has to be 90 degrees rotated on the x

hushed kettle
#

its soo odd tho.. b/c the main gameobject container has a 0,0,0 transform..

#

i was thinking it would translate fine..

haughty crystal
#

I always have my objects in blender so that their rotation is (90, 0, 0)

hushed kettle
haughty crystal
#

And export into unity without messing with the FBX export settings

hushed kettle
#

it seems to depend on wether ive rotated the obj in blender or not

haughty crystal
#

Pretty sure it's always 90, 0, 0 for me

hushed kettle
#

applying the rotations cause more issues i think

#

yet they're still carrying over a rotation. it looks like north wall vs east wall kinda situation

#

i think i know what to do

#

since somethings jank w/ the environment i think i'll extract the interactable objects out of the collection

#

and instead of trying to rotate things to the default position i want.. i'll do that in unity instead

#

i dont think i've yet figured out the best way to rotate things on a single axis yet

haughty crystal
#

I just like to setup my blender files so that their default rotation in unity is always (0, 0, 0). The blender rotation doesn't matter to me

hushed kettle
#

i always end up using movetowards pre- direct settin the transform via a quaternion funct

haughty crystal
#

Stop reading from euler angles, use a float for the angle

boreal widget
haughty crystal
#

Use MoveTowards (Or MoveTowardsAngle if it needs to wrap/loop) to move that float towards the target angle

haughty crystal
hushed kettle
#

ohhh

haughty crystal
#

Just saying what works for me

hushed kettle
haughty crystal
#

This way you have full control over the value(s)

boreal widget
#

if you use the blender script theres nothing you need to learn for it, it just works somehow. I was really fed up with that whole 90 degree thing too

haughty crystal
hushed kettle
# haughty crystal And then assign that to one of the eulerAngles axis
    public float speed = 5f;
    [SerializeField] private bool isOn = false;

    public float min = -45f; // off
    public float max = 45f;  // on

    private float currentAngle;

    private void Start()
    {
        currentAngle = isOn ? max : min;
        transform.localRotation = Quaternion.Euler(0f,0f,currentAngle);
    }

    private void Update()
    {
        float targetAngle = isOn ? max : min;
        currentAngle = Mathf.MoveTowards(currentAngle,targetAngle,speed * Time.deltaTime);
        transform.localRotation = Quaternion.Euler(0f,0f,currentAngle);
    }```
boreal widget
#

Then you can use the quaternion methods to rotate it from the start to end or vice versa

haughty crystal
#

I realized that I (ab)use .blend files a lot so was worried that the method you linked won't work with them

#

But seems like it covers .blend files so that's awesome

hushed kettle
#

thats been my approach X Axis

#

i had to glitch out unity to get that screenshot w/ the gizmo πŸ˜„

boreal widget
haughty crystal
#

Quaternion slerping should work fine here as long as the angles don't go near 180 or -180

#

Then it might take a weird route instead of rotating around the one axis you want

#

I still think a single float would be simple and good enough for this use case

boreal widget
#

true but doesnt that issue also exists with the current setup too since its using Mathf.MoveTowards?

haughty crystal
#

Yeah i did mention the difference of MoveTowards vs. MoveTowardsAngle, just depends if you want it to loop around or not

boreal widget
#

ah ok

haughty crystal
#

For a lever, MoveTowards should do it

#

As long as the angles aren't over -180 or 180, yeah

boreal widget
haughty crystal
#

I see what you're saying, similiar issue

hushed kettle
haughty crystal
hushed kettle
#

and then just use a pos and neg matching property

#

i could even use abs() to do comparisons if needed

haughty crystal
#

Some features I haven't got working in .blend files, like animations, so for those I use FBX

#

I work very iteratively so I can't be arsed to export a whole FBX instead of just hitting Ctrl + S πŸ˜„

haughty crystal
boreal widget
#

didn't know it worked like that but yea I see, when I was trying to figure out some small issue i adjusted the file like 15 times and kept exporting. its so annoying