Teleport by set amount from forward vector C++

You could be colliding with something. Check the return of SetActorLocation and maybe pass in the OutSweepHitResult variable for more info.

I think you may be onto something there.
I’ve added a second log which is the FHitResult and the location which it returns is not the same one that I expected.

LogTemp:Warning: Previous Location: X=0.423 Y=-0.906 Z=0.000, NewLocation: X=21.153 Y=-45.305 Z=0.000
LogTemp:Warning: HitResult: bBlockingHit:True bStartPenetrating:False Time:0.006880 Location:X=-309.636 Y=88.372 Z=207.080 ImpactPoint:X=-309.635 Y=88.372 Z=130.280 Normal:X=-0.000 Y=0.000 Z=1.000 ImpactNormal:X=-0.000 Y=0.000 Z=1.000 TraceStart:X=-313.074 Y=89.769 Z=209.229 TraceEnd:X=21.576 Y=-46.211 Z=0.000 PenetrationDepth:0.000000 Item:-1 PhysMaterial:N
one Actor:Floor Component:StaticMeshComponent0 BoneName:None FaceIndex:-1

I’ve also made a slight alteration to the SetActorLocation code as I believe this before would of returned an incorrect value.

bool Success = SetActorLocation(Direction + NewLocation, true, &OutSweepResult);

I also tried rotating the player start by 180 degrees. To try and determine if the Forward Vector I was getting was incorrect, but again the character only teleported in one direction.

Just after I replied I had another look through the log message and I found the issue. It was the values I was passing into the SetActorLocation

Previously I was passing in Direction, which was the Vector that represented the way the player was facing:

bool Success = SetActorLocation(Direction + NewLocation, true, &OutSweepResult);

What I actually wanted was to pass in the current GetActorLocation and add the NewLocation to that.

bool Success = SetActorLocation(GetActorLocation() + NewLocation, true, &OutSweepResult);

Thanks for pointing me in the right direction!

Hello,

I’m working on a 3D project within Unreal but am running into issues with a blink ability/teleport ability I am coding.
For some reason my character does teleport, but only in one direction, from what I can see this is the X axis.
Most of the examples I can find on this topic are using blueprint, in which I am struggling to convert into working C++.
I’ve also included the log, which to me returns what I would expect. The project is built on top of the Third Person platformer template within Unreal.
Any help would be greatly appreciated, I’ve attached a code snippet below of the blink method.