Hi,
Obviously I am new to the whole UE thing
What I am trying to do.
I have a cable which is bend like this:
On each of the end I have a line trace to check if it is “hitting” something.
This is the simplified method I have.
void ABaseCableItem::TraceInDirection(FVector direction, FVector offset)
{
FVector loc;
FRotator rot;
FHitResult hit;
ABaseCableItem* hitItem;
// Transform vectors in relation to local transform of the actor
FVector relativeOffset = GetActorTransform().InverseTransformVector(offset);
FVector relativeDirection = GetActorTransform().InverseTransformVector(direction);
loc = GetActorLocation() - relativeOffset ;
FVector start = loc;
FVector end = (start - relativeDirection) ;
// Add the actor itself to be ignored for the trace
FCollisionQueryParams params;
params.AddIgnoredActor(this);
bool bHit = GetWorld()->LineTraceSingleByChannel(hit, start, end, ECC_Cable, params);
}
Offset Vector is the vector to offset the starting point for the trace and direction …the direction
Calling it would look like this:
TraceInDirection(FVector(-50, 0, 0), FVector(-50, 0, 0));
TraceInDirection(FVector(0, -50, 0), FVector(40, 100, 0));
I was expecting that InverseTransformVector takes rotation into consideration. It seems like it does not. If the actor (the cable) is getting rotated around the X axis (rolled) the whole trace does not work anymore. Starting point offset and direction always seems to have the wrong rotation. It seems like it rotates but not correctly.
Here is how it would look like.
Probably hard to see - bottom one is correct. From both ends the line trace comes. Upper one is rotated by X 90, and the trace if completely off.
I guess I will have to take rotation into consideration when I inverse the vectors. Just not sure how. I tried to get the rotator of the actor and rotate the offset and direction, but was not working.
Any hint what I may missed? Getting really frustrated with that.
Thanks for any tip or advice (even more for a solution)