I’m working on a game where we feature wall climbing. I have a working system for getting a ledge from my actor mathematically, but it only works when the actor is rotated in one axis and only on two of the sides.
Here is an image of the “wall”:
[SPOILER]
I get the point where I want to grab the ledge by getting the location of the two arrows and tracing from the character to the wall. Then I do some vector math and the sinerule. But the problem I am facing is that I can’t really get the vector from the hit location along the face, pointing upwards to the sky. Right now it just traces perpendicular to the plane.
FVector APlayerCharacter::GetNormalPointFromB(FVector ForwardVector, FVector PointA, FVector PointB, FVector PointC)
{
FVector VectorAB = PointB - PointA;
FVector VectorAC = PointC - PointA;
FVector VectorBD = (PointB + ForwardVector) - PointB;
FVector VectorBA = PointA - PointB;
double AngleBAD = UKismetMathLibrary::Acos(FVector::DotProduct(VectorAB, VectorAC) / (VectorAB.Size() * VectorAC.Size()));
double AngleABD = UKismetMathLibrary::Acos(FVector::DotProduct(VectorBA, VectorBD) / (VectorBA.Size() * VectorBD.Size()));
double AngleADB = UKismetMathLibrary::GetPI() - AngleBAD - AngleABD;
double BD = (VectorAB.Size() * UKismetMathLibrary::Sin(AngleBAD)) / UKismetMathLibrary::Sin(AngleADB);
return PointB + VectorBD * BD;
}
Here is a representation of what is going on in geogebra:
[SPOILER]
Which doesn’t really work when the ledge is not perpendicular to the horizon.
[SPOILER]
The function takes a vector pointing towards line AC that is one unit long. And I simply need to rotate the vector slightly so that it points straight up the wall from the ground, not 90 degrees on line AC.
An example of what I am thinking of:
[SPOILER]
[/SPOILER]
Is there as simple way of rotating it that way based on the rotation of the actor or something? Rotators are basically french to me.