Purple curve it is surface, begin it is actor location(projectile spawn point) and end it is mouse click location. Now, projectile moves on the green line.
I want to set projectile trajectory on the blue tangent line, but doesnt know how to detect blue point. Does engine have an effective ways to detect it?
If you have no spline that describes the surface, you may need to rely on tracing and calculating right vector of normal. if you had a spline, you could read the tangent directly.
So we’re on the same page: you want a projectile to follow the curvature of a surface, right?
I have implemented iterative approach, incrementing Z axis and using line trace. But efficiency is questionable(when number of projectiles per second too high)
I have changed main idea, and now we looking for not tangent point, but vector perpendicular to normal of traced hit point, based on source direction, so func looks like this:
bool GetDirectionNormal(FVector& newDirection, const FVector spawnPoint, const FVector clickPoint) {
auto world = GetWorld();
if (world == nullptr) {
return false;
}
FHitResult hitResult;
if (!world->LineTraceSingleByChannel(hitResult, spawnPoint, clickPoint, ECollisionChannel::ECC_Visibility)) {
return false;
}
auto oldDirection = (clickPoint - spawnPoint).GetSafeNormal();
auto projection = FVector::DotProduct(oldDirection, hitResult.ImpactNormal) * hitResult.ImpactNormal;
newDirection = (oldDirection - projection).GetSafeNormal();
return true;
}
And result(it is not so good when we talk about too high objects):