ue4 bullet firing function

1. Write ray detection in the widget that creates the crosshair, and obtain the position where the crosshair should hit. Pay attention to the position of the crosshair.

 2. Get the size of the viewport through the playercontroller, multiply the size by the alignment of the crosshair (image) plus the position of the crosshair, convert the 2d vector into a 3d vector through convertScreenLocationToWoldSpace (should be), and obtain the shot position through ray detection.

 

 3. Click on the character, select the part you want to launch to create a socket.

 Create a component scene under the character mesh and bind the created socket.

 4. Create an actor to make the bullet. Add the components sphere and projectileMovement, add a ball under the sphere, and set the size of the ball through the ball's scale. Set size via sphere Radius. Set the initial speed and max speed in projectileMovement to determine the bullet speed.

 

 5 Get the direction of the bullet by finding look at rotation in character.

 

The variable loc(vector) is created in the game instance, gets the value in the widget, and uses the value in character.

Guess you like

Origin blog.csdn.net/m0_72249574/article/details/128515912