Is there a way to get if an Actor is moving in a similar direction or opposing direction from Right Vector?
Get velocity, normalize it, get dot product between the normalized velocity vector and the actor right vector. If the result is > 0, it’s moving right, and vice versa.
P.S.
If you only need to know if it’s moving right or left, normalizing isn’t even necessary.
For some reason every time I try Dot Product it’s always 0.
Is velocity more than 0?
Yeh it is.
Pls show how you’re getting velocity.
Hit Actor from Line Trace, Get Velocity (Target is Actor).
Hi there!
As Tuerer said, you have to get the Velocity of the Actor, Normalize it, and get the Dot Product between the Normalized Velocity of the Actor and the Right Vector.
The closer the direction (Normalized Velocity) is to matching the Right Vector, the closer the value of the Dot Product will be to 1.
If the value is 0, it means it is perpendicular to the Right Vector.
Since you’re getting a reference to the Actor by Line Trace, make sure you’re getting the correct Actor, that it’s Valid, and that the Velocity you get is actually greater than 0.
I hope this helps!
As far as I’m aware the reason is that it doesn’t have any. Velocity applies to Physics or Movement.
If you’re moving the actor with AddWorldOffset or SetActorLocation, of course you’ll have no velocity. You’re basically just teleporting it around.
You can make a function in the actor that will calculate its “velocity”:
Thanks, you’ve been really helpful.
Just want to post this update but not sure if it’s entirely right. I’ve managed a way to sum it up and not store any variables however the result is either - / + not 0 or 1 but does work fine. …
It’s supposed to be positive or negative; it’s only 0 if two vectors are strictly perpendicular.
Once again, thanks for the help.