#Local - Global Transform Directional Crisis
1 messages Β· Page 1 of 1 (latest)
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) β
Might wanna modify the mesh so that it rotates around X axis, not Z axis
the script is only working per-chance. on these objects and its annoying
Eulers are applied in a certain order, IIRC it is Z -> X -> Y
X might work better
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
ya. its actually makes the most sense tbh
You haven't shown any code yet π€
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
sure, hld up
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
Gimbal lock weirdness because your mesh has to be 90 degrees rotated on the x
its soo odd tho.. b/c the main gameobject container has a 0,0,0 transform..
i was thinking it would translate fine..
I always have my objects in blender so that their rotation is (90, 0, 0)
And export into unity without messing with the FBX export settings
does ur stuff alternate? like half my objects have a 90 or -90 and half have 0..
it seems to depend on wether ive rotated the obj in blender or not
Pretty sure it's always 90, 0, 0 for me
applying the rotations cause more issues i think
ive applied almost 3/4 of these rotations i believe in blender
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
#π»βcode-beginner message reminder
i dont think i've yet figured out the best way to rotate things on a single axis yet
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
i always end up using movetowards pre- direct settin the transform via a quaternion funct
Stop reading from euler angles, use a float for the angle
you shouldnt have to do this, spazi linked me a script before which exports most things properly but also a guide on how to actually export
#πβart-asset-workflow message
Use MoveTowards (Or MoveTowardsAngle if it needs to wrap/loop) to move that float towards the target angle
Yeah I know it's not the "proper" way, i'm too used to it at this point though
ohhh
Just saying what works for me
ya thats just an old habit i havent gotten rid of π¦
And then assign that to one of the eulerAngles axis
This way you have full control over the value(s)
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
π
I'll check it out, ty π
done π
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);
}```
if your rotations are already wonky and you don't want to fix it either, one thing you could do is [SerializeField] a start and end rotation to define them in editor. Rotate the object to the position you want it to be in, then copy those to your start/end values
Then you can use the quaternion methods to rotate it from the start to end or vice versa
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
thats been my approach X Axis
i had to glitch out unity to get that screenshot w/ the gizmo π
i meant like an actual Quaternion not just the float as the rotation
[SerializeField] Quaternion startRotation;
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
true but doesnt that issue also exists with the current setup too since its using Mathf.MoveTowards?
there is this method also https://docs.unity3d.com/6000.0/Documentation/ScriptReference/Mathf.MoveTowardsAngle.html
Yeah i did mention the difference of MoveTowards vs. MoveTowardsAngle, just depends if you want it to loop around or not
ah ok
For a lever, MoveTowards should do it
As long as the angles aren't over -180 or 180, yeah
not trying to get so far into blender discussion but .blend is the actual blender scene isnt it? are you using those in unity as your model?
I see what you're saying, similiar issue
if blender would behave i'd have them all centerd at 0
Unity internally imports them as FBX
and then just use a pos and neg matching property
i could even use abs() to do comparisons if needed
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 π
Do you still have issues with this code?
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