This article just wants the mouse to click where it is to shoot the object out that way.
It is divided into 2 things:
1. The ball must be RidgitฺฺฺBody, which is a physical ball.
2. The ground scene is used to catch the ball. 3D games require a camera and lighting.
Briefly explain the code
1 Spatial part
3 Load the object first so that it can be released
4 Create a variable to reference the released object
6 Intercept the action function
7 Intercept the left mouse click
8 Create a variable to store the camera object
9 Create a variable to store the camera's original position ray value (event.position = mouse position in the program)
10 Create a variable to store the calculation value to get the mouse coordinate transformation to the position where the object will be released
12, 13, 14 print to see the value of the camera coordinate transformation and the position where the object will be released
15 Store the value of the object to be released
16 Set the position of the object to be released as the mouse position
17 Name the object to be released (not required)
18 Add it as a subsection or child of balli. This line is for releasing the object
19 apply_impulse (stationary position to give an impulse, the force that will make the object fly out, determined by looking at the printed value x=right plus left minus y=up plus bottom minus z=front plus back minus [to make the ball fly to the back Therefore, we must multiply by -1]) (This function is only used with RigidBody physics objects.)
You can see that in this game, the ball only goes to the left and right because the y-axis is set to 0.
more
more
No comments:
Post a Comment