Unity fps tutorial pdf




















Let's create a script so we can find out when the Rocket hit something. Our script only needs two public variables and one function: using UnityEngine ; using System. All that's left for us to do is Instantiate the explosion and then Destroy the rocket itself.

This is how our Rocket Prefab looks in the Inspector after adding the script to it by dragging it on there :. Now it's time for an Explosion. Yet again Unity helps us out. We already imported Unity's particles when creating the Project, and those already contain an Explosion effect that is perfectly fine for us.

Just one more thing: by default the Explosion would explode over and over again so let's select the Small Explosion prefab in the Project area and enable the One Shot option:. Alright let's create a new C Script again, this time we will call it Shoot.

This script is supposed to spawn a new Rocket whenever the player does a mouse click. It then uses the Rigidbody's AddForce method to make it fly forward:.

AddForce g. As explained in the code's comments, the only interesting part here is the transform. It's there to make the Rocket fly exactly forward exactly in the player's forward direction. If we would use transform. Now we save the script, add it to the weapon and drag the Rocket Prefab from the Project area into the Rocket Prefab slot so it looks like this:.

There is one little adjustment to be made before we can test it. Right now if the player clicks the mouse button, a Rocket would spawn exactly where the Weapon is and then fly forward into the Player's forward direction. But we told the Rocket to explode whenever it hits something - and since it spawns exactly where the weapon is, it would hit the weapon immediately. We can easily prevent this by disabling or removing all Collider components that are on our weapon or on the children of it the cubes.

If we press Play, we can now run around and shoot Rockets at things:. Let's make the game a little bit more fun by adding a few Bull's Eyes that can be used for shooting practice.

As usual we will start by creating the model with Unity's primitives:. Here is the Bull's Eye texture that we used:. Save the file and return to Unity. Drag the Sniper script to the 3Sniper GameObject. Go to the Scripts folder and create another new C script.

Name it GameUI. The Sniper script will call these after you configure it to do so. Save the script and return to Unity. SetActive false ; add the following:. This line shows the sniper scope texture when the sniper rifle is in zoom.

Save and return to Unity. All of that was to hide the gun and show the sniper scope when the player zooms. Take it for a test run by clicking Play , pressing 3 to equip the sniper and pressing the RMB to zoom. You can make it better by setting it so that the player glimpses down the scope when zooming. Click Play and press 3 to equip the sniper rifle. Expand the Position Springs and Rotation Springs for the 3Sniper and tinker with the position and rotation offset values until the scope is front of the camera.

Name the file SniperZoom then click Save again. In this case, you moved the gun up and in front of the camera so it will appear as though the player is looking down the scope, and SniperZoom is where you saved the state. Drag the SniperZoom. Just a few more tasks lie between you and sniping the day away.

Click the small selector button to the right of the Prefab field. Find and select the PistolBullet prefab. Click Play , and focus on the most distant target — you may need to turn around. Press the RMB to zoom then fire the sniper rifle! Oh, the places you can go from here. Where to start? A logical next step would be to add an assault rifle complete with realistic animations.

Remember it should shoot very quickly and have a fast-but-small recoil after each shot. Another key feature to FPS games is inventory and ammo management, which involves working with the UI.

Or pick up Unity Games by Tutorials and learn Unity from the inside out while you build four awesome games. Lean more about how the event system works by watching this official Unity Events tutorial. If you have questions, feedback or just want to ask for more UFPS tutorials, leave a comment in our forums.

Your feedback determines what we write next — so speak up! The raywenderlich. Get a weekly digest of our tutorials and courses, and receive a free in-depth email course as a bonus!

Learn iOS, Swift, Android, Kotlin, Dart, Flutter and more with the largest and highest-quality catalog of video courses and books on the internet. Anthony is a hardcore gamer and is making a game called Grrbls. You can follow along with development at www. Gijs is an indie Unity developer working from his own company www.

Gijs likes to work on educational games and art Wendy is a full-time project manager that specializes in projects that merge creative and technical. Amazing tutorial! Thank you very much. I have also encountered this issue and I tried to freeze the y axis for rotation, but when I do that, the camera rotation lose its smoothness.

Can you help me with that? Thank you very much! OverlapSphere groundChecker. Yes this could work as well! Any ideas on how can I fix this? Should I try playing around with physics materials? Yeah, you could try playing around with Physics Materials increasing a friction maybe or maybe even increasing the mass of your Rigidbody.

Whenever I rotate my camera, the camera movement is quite choppy and eye-disturbing. Any solutions to this? I copy and pasted the code to make sure everything was right, to no avail. Clamp xRotation, , 85 ;.

That is the entire script to have it work instead of placing it on the fps character put it on the camera instead, the defaults are 1 and 1 for the sensitivity but feel free to tweak as much as you would like. For some reason, if I look to north, player moves faster, if I look south, it moves slower. FPS are always GetKeyDown KeyCode.

AddForce Vector3. MovePosition transform. Hi Admin!! I actually after 2 weeks got to move my 3d player!! Or your script needs to check if the component is attached before using it. MovePosition UnityEngine. Vector3 position at :0 FPSMovement. I figure it out… I forgot to freeze rotation… but now to my real question. This is a bit more complicated. WOW thanks admin for this amazing tutorial on how to make a fps game, it helped me alot, thanks alot once again.

Is there any way to fix the character getting stuck on walls and the jittering that occurs when you collide with something? I still retain full control including the ability to look but now the view continues to rotates when not receiving new input. This was really helpful but I need some help!! What should I do if I want to move the player where the camera is facing at?

Could you help me, please? Well, if you did everything like I did in the tutorial it should already work like that. I use Terrain and when I jump on Default layer, it seems like it can jump forever. Seems like it detect the collision everywhere in the terrain. Collections; using System. Generic; using UnityEngine;. I firstly want to say, that this is a quite handy and easy to follow guide, and you have my thanks.

However, there are some small issues I want to address. First being the whole ground checking script. Perhaps some people might fancy that instead? Adding Time. Well, what are you thoughts on this? Something like this:. GetKey KeyCode. Lerp newScale. Hi, thank you for putting this up, this is about the most useful tutorial out there. Your explanations are great for a beginner with some experience. Exactly what I was looking for. Virtual Reality: Convert one of your games to be played in Virtual Reality.

Modeling: Learn the basics of Blender and how to create and animate your creations. Publishing: Learn how to export your game to your computer, web, and mobile devices. Download e-Book Pdf. Related e-Books.



0コメント

  • 1000 / 1000