Announcement

Collapse
No announcement yet.

Rotating actor relative to camera position

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Rotating actor relative to camera position

    Hello,

    Im puzzling my mind on rather simple task. Rotating actor relative to camera position (camera space). I feel like I know the basics and how it should work, but it just doesnt. Rotators are very confusing.
    I wish I could just provide axis to rotate around.

    Please check out my sample project or screenshot below. I want to rotate this cube in screen space. No matter from which direction I look at it, it will rotate along camera's x axis located in the middle of cube. Hope it make sense.

    Thanks!

    https://drive.google.com/file/d/0B7T...ew?usp=sharing


    Click image for larger version

Name:	rotation2.JPG
Views:	1
Size:	79.7 KB
ID:	1168097

    Click image for larger version

Name:	rotation.JPG
Views:	1
Size:	229.4 KB
ID:	1168098

    #2
    You can get forward, right and up vector of the camera. Then you can rotate vector around axis, for eg. forward vector of cube rotate around up vector of camera. Result will be some vector that is length 1. Then you can find rotation by applying this to find look at rotation, from [0,0,0] to your rotated vector value.

    You can also find that rotation with other nodes, but i think find look at rotation will be best here. Watch for near pole artifacts.

    Comment


      #3
      Nawrot, thanks for reply. Unfortunately, I couldnt get it working. I dont get how rotators work. Its a roll, pitch, yaw, but in a local space of rotated object right ? Then how can I convert world space axes to local space rotator. When I create MakeRotationFromAxes with [1,0,0][0,1,0][0,0,1] values, then object wont rotate at all(just for test).

      Again, here is what Im after.


      This setup gave me cube rotating in many directions, nothing consistent.

      Click image for larger version

Name:	Capture.JPG
Views:	1
Size:	201.6 KB
ID:	1094735
      Attached Files

      Comment


        #4
        here is solution:

        Click image for larger version

Name:	Capture.JPG
Views:	1
Size:	110.7 KB
ID:	1094801

        Comment


          #5
          This whole vector math on last picture is bogus.
          First you are getting vector from cube to camera.
          Then you zero X and Y, leaving only Z.
          Rotator from axis and Angle normalizes that vector.
          So if you plugged only [0,0,1] into rotator from axis you would have same result.

          Comment


            #6
            The node with big X before RotatorFromAxisAndAngle is a cross product, not multiplication.

            Comment


              #7
              Code:
              voidAInspectable::ArbitraryAxisRotation(const FVector& POVForwardAxis, const FRotator& InputRotation)
              {
              	const FQuat POVQuat = POVForwardAxis.ToOrientationQuat();
              
              	const FQuat RollQuat(POVQuat.GetForwardVector(), InputRotation.Roll); // X Axis
              	const FQuat YawQuat(POVQuat.GetUpVector(), InputRotation.Yaw); // Y Axis
              	const FQuat PitchQuat(POVQuat.GetRightVector(), InputRotation.Pitch); // Z Axis
              
              	const FQuat DeltaQuatToApply = PitchQuat * (YawQuat * RollQuat);
              	this->SetActorRotation(DeltaQuatToApply * this->GetActorQuat());
              }
              if anyone is still interested in a solution
              Thanks at [MENTION=3798]Sion Sheevok[/MENTION] (Discord) who helped me with this.


              Freelancer for UE4 and more! www.mykoncodes.com

              Comment

              Working...
              X