x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

SetActorRelativeRotation setting as world

I'm currently creating a movement script for pawn where the rotation is Slerped based on what keys are pressed and the rotation of the camera, as well as the normal of a slope. However the angle is set on world, even though i use SetActorRelativeRotation. This causes the rotation to work not as intended and the angle pivots on the worlds upward vector, and not the actor's.

 FHitResult hit1;
     GetWorld()->LineTraceSingleByChannel(hit1, GetActorLocation() + FVector(0, 0, -47), GetActorLocation() + FVector(0, 0, -97), ECC_Visibility);
     DrawDebugLine(GetWorld(), GetActorLocation() + FVector(0, 0, -47), GetActorLocation() + FVector(0, 0, -97), FColor(255, 0, 0),true);
 
     newRotation = FRotator(0, angle, 0) + FRotator(0, camera->GetComponentRotation().Euler().Z, 0) + FRotator(hit1.Normal.Rotation().Pitch, 0, 0);

     if(forward != 0 || right != 0)
         SetActorRelativeRotation(FQuat::Slerp(GetActorRotation().Quaternion(), newRotation.Quaternion(), 0.05f));

Product Version: UE 4.12
Tags:
more ▼

asked Aug 03 '16 at 09:49 PM in C++ Programming

avatar image

Jet0610
41 2 6 7

avatar image rantrod Aug 05 '16 at 01:42 AM

When you click on the little arrow in the Actor's Rotation setting in the details panel, is it set to Relative or World?

avatar image Jet0610 Aug 06 '16 at 09:16 PM

I've checked both and the values are the same

avatar image Digi Labs Dan Aug 05 '16 at 03:33 AM

Not sure, but I think you're confusing relative transform and local transform. "Relative" is relative to whatever the actor is attached to (or the world if the actor is not attached to anything). "Local" is relative to the actor's current transform.

avatar image Jet0610 Aug 06 '16 at 09:11 PM

Ah so is there a function to set the rotation locally instead of in world space?

avatar image Digi Labs Dan Aug 07 '16 at 12:11 AM

AddActorLocalRotation sets the rotation with respect to the current rotation. But note that if you do it twice, the rotation the second time is with respect to where the actor was after the first part of the rotation. Assuming newRotation is the eventual rotation you want in local space, I think what you mean to do is to first compute the final rotation (use ComposeRotators(GetActorRotation(), newRotation)) and then slerp between the actor's starting rotation and that rotation.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

I think you are looking for something like AddActorLocalRotation()

As dbouchoff statet, RelativeRotation is always relative to the parent. And if your Actor is not attached to something, it is always relativ to the World, therfore it is in world space.

Edit, if you are looking for the c++ implementation of it, you can right-click the BP node and goto the c++ implementation.

more ▼

answered Aug 06 '16 at 10:39 PM

avatar image

DennyR
1.1k 31 12 47

avatar image Jet0610 Aug 06 '16 at 11:20 PM

I've tried that too, but it doesn't set the value, it adds to the current one making it spin out

avatar image DennyR Aug 07 '16 at 12:45 AM

Are you calling this every frame? If you do, it is much easier to compute a DesiredRotation and then smootly interp to this rotation every frame.

FMath::RInterTo() should give you decent results.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question