- Newest
- Most votes
- Most comments
Hi @REDACTEDUSER
You don't need the whole GetWorldTM (believe me, I'm us).
Here is the code to get/set position/rotation/scale
//The player
AZ::EntityId m_PlayerComponentID;
//Edit scale
AZ::Vector3 vScale;
EBUS_EVENT_ID_RESULT(vScale, m_PlayerComponentID, AZ::TransformBus, GetLocalScale);//Get scale
EBUS_EVENT_ID(m_PlayerComponentID, AZ::TransformBus, SetLocalScale, vScale);//Set scale
//Edit position
AZ::Vector3 vPos;
EBUS_EVENT_ID_RESULT(vPos, m_PlayerComponentID, AZ::TransformBus, GetLocalTranslation);//Get position
EBUS_EVENT_ID(m_PlayerComponentID, AZ::TransformBus, SetLocalTranslation, vPos);//Set position
//Edit rotation
AZ::Quaternion quatPlayerRotation;
EBUS_EVENT_ID_RESULT(quatPlayerRotation, m_PlayerComponentID, AZ::TransformBus, GetWorldRotationQuaternion);//Get rotation
EBUS_EVENT_ID(m_PlayerComponentID, AZ::TransformBus, SetLocalRotationQuaternion, quatPlayerRotation);//Set rotation
Wait a minute, your Set
method for position/rotation/scale will remove the others, won't it?
I think the scale, rotation, scale is all bundle inside WorldTM(), Do you know how to update each of them? This question is about update each of them :)
Yes just use Interface inside AZ::Transform "dev\Code\Framework\AzCore\AzCore\Math\Transform.h"
Thank Anatoliy, I see that there is function
SetRotationPartFromQuaternion(), so this could be the way to set rotation, but how about getting rotation?
AZ::Quaternion quat = AZ::Quaternion::CreateFromTransform(someTransform);
Hi HDN, Looking good.If i try create get Transform and then set him to different Entity i create code like you.
EBUS_EVENT_ID_RESULT(playerTM, m_PlayerEntityId, AZ::TransformBus, GetWorldTM);
EBUS_EVENT_ID(m_cameraEntityId, AZ::TransformBus, SetWorldTM, playerTM);
Thank @REDACTEDUSER
I really want to accept your answer, but your answer doesn't show how to get/set each item: position/rotation/scale.
all ok :)
First Get Second Set;
Position
AZ::Vector3 position = someTransform.GetTranslation();
AZ::Transform newTransform = AZ::Transform::CreateTranslation(newPosition)<br>
Rotation
AZ::Quaternion quat = AZ::Quaternion::CreateFromTransform(someTransform);
AZ::Transform newTransform = AZ::Transform::CreateFromQuaternion(quat);
Scale
AZ::Vector3 scale = someTransform.ExtractScale();
AZ::Transform newTransform = AZ::Transform::CreateScale(newScale);
p.s
About scale i trying not working with scale.
p.s. 2
If you want understand how work with Transform Matrix And Quaternions read in math docs it is very big part math.
"Wait a minute, your Set
method for position/rotation/scale will remove the others, won't it?"
Can`t understand ? You mean if i set position i remove rotation ? If i understand correctly, you must combine all transforms to one using multiplication.
Example:
AZ::Transform onlyPosition = ...;
AZ::Transform onlyRotation = ...;
AZ::Transform rotationAndPosition = onlyPosition * onlyRotation;
Read more about Transform Matrix And Quaternions on math docs.
About accepting don`t worry :)
You understand correctly, but I found a better way to edit the transform (please check my answer). Thanks for your help.
Thanks for the info, I didn't want my question to clutter the answer space.
This post is closed: Adding new answers, comments, and votes is disabled.
Relevant content
- Accepted Answerasked 4 years ago
- Accepted Answerasked 4 years ago
- Accepted Answerasked a year ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 5 months ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 2 years ago