How to get angle at which player is facing?
My player is an FPS controller. When the player left clicks and is close enough to the surface that they are facing, they should launch in the opposite direction of where they are facing (ex. they face straight down at the floor so they launch straight up). Currently, the player can left click from anywhere and only goes straight up.
asked Dec 28 '17 at 04:08 AM in Blueprint Scripting
You can do this with a line trace. First, get actor's rotation and then it's forward X vector to determine the direction of Line Trace. Break the Hit result and on a successful hit, the Impact normal will give you the normal vector of the surface. You can then find the angle between your actors forward X vector and this normal by taking the ArcCos of the dot product between these two vectors. The following picture shows its implementation in the Character's blueprint.
Hope this helps.
Please don't forget to rate this answer if it helped in resolving your issue. Thanks.
answered Dec 28 '17 at 04:26 AM
Presumably there is a First Person Player Camera?
Get the forward vector to see the direction the player is looking (it's a unit vector with magnitude 1.0f), multiply the vector by -1 to get the unit vector of your impulse (to launch them) and then scale the inverted forward vector by the magnitude of your launch.
answered Mar 25 '19 at 09:04 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here