![]() Pressing either of these keys adds a force to the cube rigidbody using rigidbody.AddForce. In this case, you are looking for presses of the W and S keys. You can use Input.GetKey to determine when a key is being pressed. This code is nice and simple you just need two if statements, one for forward movement, and one for moving backward. Now you can add some code that will get your player model moving. The camera will automatically follow your cube with this done. Go to the hierarchy pane before dragging and dropping the camera onto the cube to create a parent-child relationship. Position the camera so that sits in a comfortable third-person position above your cube. Your scene should already have a camera you can use as your third-person camera. You can find free Unity assets online to spruce your project up. Tick the Use Gravity tickbox and leave the rest of the settings as they are. Click on Add Component at the bottom of the pane, search for rigidbody, and select Rigidbody from the list when it appears. You also need to add a rigidbody component to make the cube into a physics object. Position the new cube so that it sits above the plane you’ve also added. Right-click inside the hierarchy pane, hover over 3D Object, and select Cube from the drop-down menu. ![]() Next, it’s time to add a cube to the scene to act as a player model. You can adjust the size of the plane to provide a larger testing area, but you don’t need to do anything else to it. Right-click inside the hierarchy pane, hover over 3D Object, and select Plane from the list. The first object to add to your scene is a plane.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |