|
1 | 1 | Title: 3d Characters
|
2 | 2 | Description: How to control 3D characters with HappyFunTimes
|
3 | 3 |
|
| 4 | +I wanted to include a 3D game but I don't own any 3D assets |
| 5 | +and it seemed improper to include Unity's Standard Assets |
| 6 | +so, here are the instructions to create a 3D example |
| 7 | +from scratch. I'm only guessing it will take around 20-30 minutes |
| 8 | +(5 minutes if you've already done it once). |
| 9 | + |
| 10 | +It will hopefully also be a good tutorial on how to take |
| 11 | +something that's already designed to work with controllers |
| 12 | +and make it work with HappyFunTimes |
| 13 | + |
4 | 14 | Follow these steps
|
5 | 15 |
|
6 | 16 | * Make a new project
|
@@ -54,14 +64,20 @@ Follow these steps
|
54 | 64 | The steps are
|
55 | 65 |
|
56 | 66 | 1. rename it `ThirdPersonUserControllerHFT`
|
57 |
| - 2. add a `private HFTInput m_hftInput;` |
58 |
| - 3. In `Start` set `m_hftInput = GetComponent<HFTInput>();`; |
59 |
| - 4. In `Update` check for `m_hftInput.GetButtonDown("fire1");` |
60 |
| - 5. In `FixedUpdate` add in `+ m_hftInput.GetAxis("Horizontal")` and |
| 67 | + 2. add a `private HFTInput m_hftInput;` and `private HFTGamepad m_gamepad;` |
| 68 | + 3. In `Start` set `m_hftInput = GetComponent<HFTInput>();` and `m_gamepad = GetComponent<HTFGamepad>();`. |
| 69 | + 4. Add `m_gamepad.OnDisconnect += Remove`; |
| 70 | + 5. Add a `Remove` method that calls `Destroy`. |
| 71 | + 6. In `Update` check for `m_hftInput.GetButtonDown("fire1");` |
| 72 | + 7. In `FixedUpdate` add in `+ m_hftInput.GetAxis("Horizontal")` and |
61 | 73 | `- m_hftInput.GetAxis("Vertical")`
|
62 |
| - 6. Also add `m_hftInput.GetButton("fire2")` to the crouch check |
| 74 | + 8. Also add `m_hftInput.GetButton("fire2")` to the crouch check |
| 75 | + |
| 76 | + <img width="696" height="342" src="images/3d-011-edit-script.gif" /> |
63 | 77 |
|
64 |
| - <img width="643" height="353" src="images/3d-011-edit-script.gif" /> |
| 78 | + <a href="assets/3d-step1-diff.html" target="_blank">Here's a diff of the changes (click here for a new tab)</a>. |
| 79 | + |
| 80 | + <iframe src="assets/3d-step1-diff.html" width="900" height="500"></iframe> |
65 | 81 |
|
66 | 82 | * Select the prefab again
|
67 | 83 |
|
@@ -90,5 +106,57 @@ Follow these steps
|
90 | 106 |
|
91 | 107 | Hopefully that shows how simple it is to get started.
|
92 | 108 |
|
| 109 | +## Colors and Names |
| 110 | + |
| 111 | +Let's had a little more code to show names and colors. |
| 112 | + |
| 113 | +<a href="assets/3d-step2-diff.html">Here are the changes to the script (click here for a new tab)</a>. |
| 114 | + |
| 115 | +<iframe src="assets/3d-step2-diff.html" width="900" height="500"></iframe> |
| 116 | + |
| 117 | +We added a `nameTransform` Transform public field. We need to set that to a transform **inside the prefab** |
| 118 | +so we'll follow these steps |
| 119 | + |
| 120 | +1. Drag the `ThirdPersonController` prefab into the scene hierarchy |
| 121 | +2. Create a GameObject. |
| 122 | +3. Drag the GameObject under the root of the prefab |
| 123 | +4. Rename it to `name` (or anything) |
| 124 | +5. Move it above the character's head |
| 125 | +6. Drag it to the `Name Transform` field of our `ThirdPersonUserControlHFT` script. |
| 126 | +7. From the menus pick `GameObject->Apply Changes to Prefab` |
| 127 | +8. Delete the prefab from the scene |
| 128 | + |
| 129 | +Here's a silent video of the steps |
| 130 | + |
| 131 | +<iframe width="853" height="480" src="https://www.youtube.com/embed/Sp2-vWM14_M" frameborder="0" allowfullscreen></iframe> |
| 132 | + |
| 133 | +Now run it. There should be a "name" box showing the players name in a color matching |
| 134 | +the player's controller. |
| 135 | + |
| 136 | +<img width="637" height="389" src="images/3d-120-run.gif" /> |
| 137 | + |
| 138 | +**NOTE**, this way of showing names is **not** the recommended Unity way. The point of this example |
| 139 | +is to show how to use HappyFunTimes to set colors and read names, **not how to use Unity**. |
| 140 | +To display names the Unity way please [search for examples](https://www.google.com/search?q=displaying+a+name+above+a+character+unity). |
| 141 | + |
| 142 | +Similarly in the example above all players spawn at the same place and if they fall over the edge |
| 143 | +of the world they fall forever. [Spawning at random locations](https://www.google.com/search?q=unity+spawn+at+random+location) |
| 144 | +and [dying or resetting if the player falls off the world](https://www.google.com/search?q=reset+when+player+falls+of+world+unity) |
| 145 | +are standard Unity game development issues and have nothing to do with HappyFuntTimes. |
| 146 | +While I want to be helpful I can't teach you Unity. I can only teach you HappyFunTimes. For Unity issues |
| 147 | +please use the [Unity Forums](https://forum.unity3d.com/) and/or [Unity Answers](http://answers.unity3d.com/). |
| 148 | +Also see the samples. |
| 149 | + |
| 150 | +The Simple and Clean examples in `Assets/HappyFunTimes/MoreSamples` spawn players at random locations given a globally defined area. |
| 151 | +For Spawn points you can apply ideas from the example above. On the LevelManager (or some global object) |
| 152 | +you make an array of `Transform`s. `public Transform[] spawnPoints;` |
| 153 | +You then make a bunch of GameObjects, as many as you want, one for each spawn point and add them to the list |
| 154 | +of spawn points Unity just like we added the `name` GameObject to the `nameTransform` above. When player |
| 155 | +is added, then either in their `Start` or `InitNetPlayer` functions (if you're not using the HFTGamepad) |
| 156 | +you'd find that list and either pick one of the spawn points at random or pick the next one or whaever fits |
| 157 | +your game. Again, these are Unity game development issues not HappyFunTimes issues. I hope that doesn't |
| 158 | +come across as harsh but I also hope you see my point. |
| 159 | + |
| 160 | + |
93 | 161 |
|
94 | 162 |
|
0 commit comments