Hello,I seem to have diffuclties to understand this function.the return type the name it kind of confuses me.
why did they even name it SuggestProjectileVelocity ? the word suggest here is weird for me. also in parameters there is a FVector TossVelocity and a float TossSpeed.i’m okay with float TossSpeed but TossVelocity… no.
in physics we say Speed is a scalar quantity(amount without direction),and velocity is speed with direction.but here TossVelocity is a FVector ? FVector is simply a Vector containing three values in x,y,z,because of the name i dunno what the value that the function returns as TossVelocity is and what does it mean.
can anyone clear me ? i also logged it in UE4 log i couldn’t figure out what it is actually. thanks in advance
I’m confused. Your wording suggests there’s a contradiction but there isn’t. FVector is a vector (hence the name) i.e. not a scalar and TossVelocity is a velocity (also a vector).
i’m sorry.I also meant velocity isn’t a scalar but if we say it’s a FVector it means it only has a direction not also the amount of speed.and even if i can get along with this i wanna know what that location that it tells us as a FVector is ? the location seemed to be a huge number like :x=5607,y=7608,z=4869. i don’t think it is a location of sth like our HitLocation.
That’s not true.
It’s not a location, it’s the TossVelocity.
my problem is that i don’t get what TossVelocity is exactly ?where is the start point and the endpoint of it?
There isn’t one. It’s just a direction and magnitude.
when we say TossVelocity.GetSafeNormal() y it becomes sth like a direction.but before that the x,y and z are too mcuh to just show a direction and also i don’t see any magnitude ? x,y,z where is the magnitude ?
Part of the X,Y,Z. That’s what GetSafeNormal is doing, removing the magnitude.
Toss direction will be equal to the direction that turret is looking at ?and later we trying to set it with the direction we are looking at to move the turret to that direction ?
Which is TossDirection? Looking at the code Ben doesn’t name anything TossDirection.
i said it according to the function parameter name.Ben named it OutLaunchVelocity.you said GetSafeNormal removes magnitude so there will be only the direction there.if you are confused that what i actually mean,then i suppose it like this: i only dunno what is that TossVelocity(OutLAunchVelocity) and when Ben uses the code:OutLaunchVelocity.GetSafeNormal() and logs it out we have a unit vector right ?.a Vector always have a start point and an endpoint i only cannot know these two points.so i cannot visualize how does it look like.
I figured but I just wanted to double check so I wasn’t going to make an incorrect assumption :).
So back to
It’s not what the turret (or barrel) is looking at but what they need to look at. i.e. The barrel needs the TossDirction’s pitch and the turret needs the yaw.
Maybe this code will help you understand
FVector Start = Barrel->GetSocketLocation(TEXT("Projectile"));
DrawDebugLine(GetWorld(), Start, Start + OutLaunchVelocity, FColor::Blue, false, -1.f, '\0', 100.f);
i used it i’m getting a horrible result xD a blue line is going staright up to the sky.
i also tried to use
FVector EndLocation=Start+OutLaunchVelocity.GetSafeNormal() ;
i thought with this its gonna be a small vector but this time it’s going down to the ground and the other weird thing is that in this case only AIPlayers have that DebugLine and the Main Player doesn’t have it.
Then are you sure Start is correct? Did you name your socket something else?
no it’s correct and the start point is exactly there also
do you have the code to try it ?if u have how does it look like for you ?
FVector OutLaunchVelocity;
FVector StartLocation = Barrel->GetSocketLocation(FName("Projectile"));
bool bHaveAimSolution = UGameplayStatics::SuggestProjectileVelocity
(
this,
OutLaunchVelocity,
StartLocation,
HitLocation,
LaunchSpeed,
false,
0,
0,
ESuggestProjVelocityTraceOption::DoNotTrace // Paramater must be present to prevent bug
);
if (bHaveAimSolution)
{
AimDirection = OutLaunchVelocity.GetSafeNormal();
FVector Start = Barrel->GetSocketLocation(TEXT("Projectile"));
DrawDebugLine(GetWorld(), Start, Start + OutLaunchVelocity, FColor::Blue, false, -1.f, '\0', 100.f);
now mine also works.the debug line Starts from our startpoint and to whereever we aim.so it means it is making a line to the HitLocation .i also tried to use Start+HitLocation istead of third parameter it has to be the same with the one i tried before cuz HitLocation is where that whiteDot is looking at but it’s a little different why? why is it precise for Start + OutLaunchVelocity but not precise for Start + HitLocation? here is the picture for:
DrawDebugLine(GetWorld(), Start, Start + OutLaunchVelocity, FColor::Blue, false, -1.f, '\0', 100.f);

and here is for :
DrawDebugLine(GetWorld(), Start, Start + HitLocation, FColor::Blue, false, -1.f, '\0', 100.f);

any idea why ?also HitLocation of AITanks are MainPlayerTank why are they aiming somewhere else in this case ?
HitLocation is a location and not a velocity so it already is the end point, you don’t add Start to it.
The red line is a straight line directly from the Start to the HitLocation. The blue line is Start + OutLaunchVelocity and is what the barrel/turret need to aim at in order to hit that location with the given LaunchSpeed.
