How to get FollowCamera as LineTrace Startpoint ?

Hey Folks,

im pretty new to the Coding stuff and at the Moment im trying to do a simple
“Grab an object and throw it away. If it smashes on the Ground it plays a sound and the Enemy is watching at this Point so u can pass him.”

Well the Enemy is setup correctly and can hear sound and see me.
The Problem is i dont know how to get the FollowCamera via LineTraceSingleByChannel correctly as Startingpoint …

In Blueprint i got it setup correctly but in C++ i dont know how to access it the right Way.

BP Setup

C++ Setup

I was trying to recreate it in C++ from the BP System but it dont wanna work ^^

Im pretty lost at this Point…

Ok so the LineTrace is working correctly now it was just working with FollowCamera->GetComponentLocation() ^^

Are you sure this code is correct? ForwardVector is just a static FVector(1, 0, 0) so no matter where you are looking, it is going to point to the same direction. FRotator::Vector() is going to “Convert a rotation into a unit vector facing in its direction.” So you don’t need ForwardVector.

The ForwardVector was just a fail ^^

FHitResult ACharacter_Player::GetHitResult()
	FHitResult Hit;
	FVector Start = FollowCamera->GetComponentLocation();
	FVector End = Start + (FollowCamera->GetComponentRotation().Vector() * 1500.0f);
	FCollisionQueryParams TraceParams(FName(TEXT("")), false, this);
	GetWorld()->LineTraceSingleByChannel(OUT Hit, Start, End, ECC_PhysicsBody, TraceParams);
	return Hit;

so thats how i did it now :slight_smile:

1 Like