Can not understand the meaning of Rotation param in UGameplayStatics::SpawnEmitterAtLocation

I am drawing a debug line to see the shoot direction and so on…
But the thing is that I can not get why should I specify Rotation to the UGameplayStatics::SpawnEmitterAtLocation function…
So the Hit.ImpactNormal should return the opposite normalized vector of shooting, isn’t it?


UGameplayStatics::SpawnEmitterAtLocation(GetWorld(), ImpactEffect, Hit.ImpactPoint, Hit.ImpactNormal.Rotation());

What could go wrong if I specify FRotator(0,0,0) instead of Hit.ImpactNormal.Rotation()?
I will not be able to get the ImpactDirection from an actor or a pawn, which I would hit or what?

Hit.ImpactNormal.Rotation() returns the

Hit.ImpactNormal description:

Image how I understood it. The red Line is a normalized vector pointing out from the plane
[SPOILER]
https://snipboard.io/xIgqQa.jpg
[/SPOILER]

  1. Who can explain me please the meaning of normalized vector in this situation and other in much details as it would be possible for you!
  2. How does it transform the normalized vector into rotation?

I will do appreciate it!:slight_smile:

I strongly advise you to use blueprints before jumping to c++ because such questions should be tested and understood by yourself and using blueprints you can play around safely with everything

This is normal. It perpendicular to the plane it points out.

Vector to Rotator conversion is done by using vector direction to determine pitch and yaw while roll will be zeroed because Up vector wasn’t specified
look for Vector -> Rotator conversions in KismetMathLibrary

I tested this one and the Hit.ImpactNormal.Vector(); and There was no difference in what I could see visually.

Thanks, Yeah, I do use BPs.

What the use of the normalized vector, I can not understand where I can use the normal vector which has length one (a unit vector)?
Could you please give me some real examples? and what does it mean normal vector which length is equal to one? So what is it for and how can I imagine it in a game?

Yeah, I use VisualAssist for it and using ALT+G I can go to the function definition and read about it, but that not always helpful to start from, especially if you see it at first.

I found the comments:

and the func



// from UKismetMathLibrary
KISMET_MATH_FORCEINLINE
FRotator UKismetMathLibrary::Conv_VectorToRotator(FVector InVec)
{
    return InVec.ToOrientationRotator();
}

// unrealmath FVector class` function

FRotator FVector::ToOrientationRotator() const
{
    FRotator R;

    // Find yaw.
    R.Yaw = FMath::Atan2(Y,X) * (180.f / PI);

    // Find pitch.
    R.Pitch = FMath::Atan2(Z,FMath::Sqrt(X*X+Y*Y)) * (180.f / PI);

    // Find roll.
    R.Roll = 0;

#if ENABLE_NAN_DIAGNOSTIC
    if (R.ContainsNaN())
    {
        logOrEnsureNanError(TEXT("FVector::Rotation(): Rotator result %s contains NaN! Input FVector = %s"), *R.ToString(), *this->ToString());
        R = FRotator::ZeroRotator;
    }
#endif

    return R;
}
 

and what is the

I know that tan = sin/cos // the ratio of the opposite leg to the adjacent.
What is Atan2?

A unit vector is a very convenient way to describe the direction and some operations require unit vector to work properly.
Atan2 is thing that gives the angle using two sides of right triangle.

And now, if you don’t want to stumble in the dark go to the Youtube/Wiki and learn Vector Algebra and Trigonometry

This thread seems to have gotten overly complex.

If you made your emitter facing +Z



FRotator EmitterRotation = FRotationMatrix::MakeFromZ(Impact.ImpactNormal).Rotator()'


Alternatively, if you made the emitter facing +X:



FRotator EmitterRotation = FRotationMatrix::MakeFromX(Impact.ImpactNormal).Rotator()'


Is that simple. The default FVector::Rotation() would give the same result as MakeFromX.

Hello Bargest2!

Yeah, I’ve been googling for some time. It gives me much info, but not all, which I wish to know.
I am going to do a bit more research on it!

I wanted to know where I can use it(so I partially satisfied with answer).
But How I can image it in reallife or in game?

It would be so nice if you can advise me on some literature(web-sources)…:slight_smile:

Thank you!

Good day, TheJamsh!

Do you mean that if my actor/pawn has the forward vector set to +Z(axis)? I can use it to get the rotation to a point I aimed for? and the same for +X(axis), right?