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"

Get center of actor in world coordinates instead of local coordinates

I'm calculating the center of an actor, but the FVector I get is in local coordinates. I need to get it in world coordinates so that I can move the center of the actor where I need it to go in the world. Code I use to get the center and my not working attempt at getting the center in world coordinates:

 /// Get center of actor
 const FVector BoundsPointMapping[8] =
 {
     FVector(1, 1, 1),
     FVector(1, 1, -1),
     FVector(1, -1, 1),
     FVector(1, -1, -1),
     FVector(-1, 1, 1),
     FVector(-1, 1, -1),
     FVector(-1, -1, 1),
     FVector(-1, -1, -1)
 };        
 const FBox EachActorBounds = HitResultComponent->GetOwner()->GetComponentsBoundingBox(true); 
 const FVector BoxCenter = EachActorBounds.GetCenter();

 /// Get center in world coordinates (doesn't work)
 FIntVector IntWorldOffset = HitResult.GetActor()->GetWorld()->OriginLocation;
 FVector WorldOffset = FVector(IntWorldOffset.X, IntWorldOffset.Y, IntWorldOffset.Z);
 FVector CenterInWorld = WorldOffset + BoxCenter; ///World offset
 PhysicsHandle->GrabComponent(HitResultComponent, FName(), CenterInWorld, true);



Product Version: UE 4.19
Tags:
more ▼

asked Jul 07 '18 at 01:55 AM in C++ Programming

avatar image

cowchin12
1 1 1

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

1 answer: sort voted first

From what I've read you can use the FTransform to switch between local and world. It seems FTransform::TransformPosition() will give you the world position and FTransform::InverseTransformPosition() will give you local position.

I haven't tested it though and can't right now, but you should try it if you can get your actor's transform.

more ▼

answered Jul 07 '18 at 08:58 AM

avatar image

ZazarLaLiche
218 2 3 7

avatar image cowchin12 Jul 07 '18 at 03:13 PM

I tried the replacing my world offset code above with this, but it did not work either. I can't find any good examples of translating local to world coordinates for some reason...

         FTransform* Tranformer = new FTransform();
         UInstancedStaticMeshComponent* HitMesh = NewObject<UInstancedStaticMeshComponent>(HitResult.GetActor());
         HitMesh->GetInstanceTransform(0, *Tranformer, true);
         MeshCenter = Tranformer->TransformPosition(MeshCenter);
(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