# Get center of actor in world coordinates instead of local coordinates

**URL:** <https://forums.unrealengine.com/t/get-center-of-actor-in-world-coordinates-instead-of-local-coordinates/428858>\
**Category:** Rendering\
**Tags:** world-position-offse, fvector, offset, unreal-engine, CPP, question\
**Created:** [July 7, 2018, 1:55am UTC](https://forums.unrealengine.com/t/get-center-of-actor-in-world-coordinates-instead-of-local-coordinates/428858 "2018-07-07T01:55:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![cowchin12](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@cowchin12](https://forums.unrealengine.com/u/cowchin12)\
**Post date:** [July 7, 2018, 1:55am UTC](https://forums.unrealengine.com/t/get-center-of-actor-in-world-coordinates-instead-of-local-coordinates/428858/1 "2018-07-07T01:55:01Z")

</div>

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);
```

---

<div class="post-metadata">

**Author:** ![ZazarLaLiche](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ZazarLaLiche](https://forums.unrealengine.com/u/ZazarLaLiche)\
**Post date:** [July 7, 2018, 8:58am UTC](https://forums.unrealengine.com/t/get-center-of-actor-in-world-coordinates-instead-of-local-coordinates/428858/2 "2018-07-07T08:58:17Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![cowchin12](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@cowchin12](https://forums.unrealengine.com/u/cowchin12)\
**Post date:** [July 7, 2018, 3:13pm UTC](https://forums.unrealengine.com/t/get-center-of-actor-in-world-coordinates-instead-of-local-coordinates/428858/3 "2018-07-07T15:13:01Z")

</div>

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);
```
