– We will now write a basic instantiation script that will place instances of the projectile prefab object into the game with force applied, when the user presses the space bar key. Once you have made the prefab object and it is in your assets delete it from the game hierarchy. In this example I am creating the prefab as a 3D cube and then adding: – Changes made to the prefab object will be inherited by all the instances of the prefab. The main thing is that prefabs are good for making multiple instances of the same element. (* you can also edit it once it is a prefab). You can do this by first creating the object in the hierarchy, adding materials to it etc, then dragging it from the hierarchy to the assets. Part 1 – Make a Projectile PrefabĬreate a prefab object that will be used for your projectile. As mentioned in the previous tutorial this makes the controls a bit more responsive, however the force movement is still there if you want it, just commented out. If you look at the script for this version I decided to apply the movement based on velocity rather than force. Now, in theory we should have a backup of the previous tutorial in its own scene and a new scene and version of the player controller script ready to update within the same Unity project. This is the same process that you had to do for the Basic Player Controller script. Adding extended player controller script.īecause this is essentially a new script added to the player object, with the player object selected in the inspector you will need to add the Camera Target object and the Movement Intensity value (not shown in the picture above). Then drag your Extended Player Controller script onto the bottom of the inspector area to add it to the player object. ![]() Then in the inspector deselect your Basic Player Controller script. public class ExtendedPlayerController : MonoBehaviour This is important or the script will throw an error. ![]() Rename it ExtendedPlayerController and in the actual script make sure the class name matched the name of the script. In your assets panel find the BasicPlayerController script that you made in the last tutorial and duplicate that also. Then make sure that you have this scene selected as the scene you are currently editing. ![]() You can duplicate a scene by first selecting it in the assets and then in the Edit menu select Duplicate. The next step is to polish them, so the movement feels "smooth".This tutorial will show you how to extend a simple player controller for Unity by adding the ability to jump and shoot projectiles.įirstly this tutorial is designed to follow on from the previous tutorial that shows you how to create a simple player controller using Unity.Ī good place to start is to make a duplicate of the initial scene created in this project and call it something like ‘Extended Player Controls’ (or whatever works for you). The consensus of what I read was that, once you understand how they work (and why you shouldn't mix booth :-/), the basics are really easy to implement. ![]() So, I stopped for a moment and just read/watched tuts on how Character Controllers and Rigid Body works. It got worse when I tried to mix solutions from different tutorials. I have 11 year of experience in web development (full-stack), but I'm barely starting with Unit圓D (6-ish weeks, spare time hobby), and my first problem was I didn't even understood what the player controller script has to do: I followed a tutorial and it worked like a charm, just a few lines of code and I can walk flawless (I'm making a top down shooter), but the second I deviated from the tutorial I got lost (I wanted to use two virtual joystick, one for movement and another for rotation, on mobile).
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |