I’m in a project in which I have an external sensor which gives me the pitch, roll and yaw of the object as well as its position in real life coordinate frame x, y, z in a script that I have attached to the main camera. I have succesfully implemented the rotation as: transform.rotation = Quaternion.Euler(rotationPitch, rotationYaw, rotacionRoll);
However, for the position, If I do: v3pos = new Vector3(position[0], position[1], position[2]); transform.position = v3pos;
It kinda works but only If I have my real object facing front, if for example I turn it 90º to the left and then move it “forward”, in reality is to the left in real world frame, it moves the camera to the left, and not forward as I would want.
I am not sure what is rotated relative to what, you would need to precise it better, but I guess the problem is you have sensor in world space and you want to move something in local space. When you construct quaternion you might want to multiply it with your positon, so it’s also rotated, but it can not work if it’s not local space. I can help more if you explain where is forward and left (you? object?) or even better - you can just draw super simple sketch of what is happening.
Imagine a real life camera facing wall A in front of it (all of this in real life), it can be rotated and move its position as I want in its unity representation as long as it has wall A in front in real life, however when I turn real life camera to Wall B (perpendicular to Wall A in real life) it rotates fine to front wall B in unity but If I move towards the wall B or parallel to it, the movement now is not the desired in Unity since its representation will move in the real world frame which does not take into account the rotation so the movement will be the same that in the wall A phase, ie If I move the real camera towards real wall B while facing it, the unity camera will move parallel to it, which is undesirable.
Hope I explained better
Can you please stop using the term “real life” unless you can explain what you mean by it because it’s absolutely meaningless to anything I understand in Unity. Sounds like you mean “global space” but I have no idea.
It still seems like you’re asking to move in the local (rotated) space of the camera but as I stated in the other thread, you can get that from Transform.forward. Or if you have some local “forward” motion vector then rotate it by the Transform.rotation and apply it. It’ll be rotated in the correct space.
Your paragraph above is about as confusing as it gets though. It’s made worse by these terms that I don’t understand.
If none of this is relevant or I’m misunderstand then I think it’s about time for some images or video perhaps.
When I say real life it literally means real life, I’m getting position data from a sensor in real life and giving it to unity via sockets, I move real life camera to move the one in unity, is not about global and local space inside unity.
This is way sketch would be the best if you want to get help.
If I understand correctly you just want to move camera in relation to it’s own “towards”.
As @MelvMay said, just rotate your vector with camera rotation and this will be your local space. If you need only rotation around Y axis you can just do Quaternion.Euler(0f, rotationYaw, 0f);
In Unity Y axis is up, you swapped Z and Y in the picture. Is this your mistake or your data is in such a format?
If format is different then you need to swap axes.
I don’t know how your device works, but it does not make sense. How rotation can affect position of your device? If you stand in some point in space it does not matter where you look at, you are still in the same position.
Exactly this. I do not follow what you want at all or how position relates to rotation if the device is giving you a world-space position. This would only be understandable if your device is giving you a local-space position somehow.
Yeah, don’t worry about axis, I swapped them accordingly.
You are right about the space, at this moment I’m talking from the top of my head since I don’t have access to the device right now but I remember this situation happening, I might be directly receiving bad positions. I will come back tomorrow to it if you still around. Thanks for your time