Survival Shooter Q&A

Hi everyone

For those of you wishing to follow the Survival Shooter tutorial with Unity 5, we have created a new version of the Project assets, along with an upgrade guide located in the root of the project.

We are busy making new projects so have not created new videos, but simply given you a guide to where in the videos you will need to do something different to the instructions onscreen.

As you'll see from the guide, not much has changed and a lot of the difficulties those of you trying to run the tutorial in 5.x have been experiencing were actually with the source assets, so that's all taken care of.

See the usual project page for a link to the new project on the Asset store which has everything you need.
http://unity3d.com/learn/tutorials/projects/survival-shooter

We recommend that you use the Unity version we tested this with or greater - Unity 5.1.1.

Thanks for Peet Lee (peteorstrike) from our team for taking care of this!

Enjoy!

Will

1 Like

Thank you very much Mr. Will.
I was having problem with Nav Mesh Generation, I hope I will find solution in the guide.
thanks

1 Like

i can't be turning with mouse please help me !! (
using UnityEngine;

public class PlayerMovement : MonoBehaviour
{
public float speed = 6f; // The speed that the player will move at.

Vector3 movement; // The vector to store the direction of the player's movement.
Animator anim; // Reference to the animator component.
Rigidbody playerRigidbody; // Reference to the player's rigidbody.
int floorMask; // A layer mask so that a ray can be cast just at gameobjects on the floor layer.
float camRayLength = 100f; // The length of the ray from the camera into the scene.

void Awake ()
{
// Create a layer mask for the floor layer.
floorMask = LayerMask.GetMask ("Floor");

// Set up references.
anim = GetComponent <Animator> ();
playerRigidbody = GetComponent <Rigidbody> ();
}


void FixedUpdate ()
{
// Store the input axes.
float h = Input.GetAxisRaw ("Horizontal");
float v = Input.GetAxisRaw ("Vertical");

// Move the player around the scene.
Move (h, v);

// Turn the player to face the mouse cursor.
Turning ();

// Animate the player.
Animating (h, v);
}

void Move (float h, float v)
{
// Set the movement vector based on the axis input.
movement.Set (h, 0f, v);

// Normalise the movement vector and make it proportional to the speed per second.
movement = movement.normalized * speed * Time.deltaTime;

// Move the player to it's current position plus the movement.
playerRigidbody.MovePosition (transform.position + movement);
}

void Turning ()
{
// Create a ray from the mouse cursor on screen in the direction of the camera.
Ray camRay = Camera.main.ScreenPointToRay (Input.mousePosition);

// Create a RaycastHit variable to store information about what was hit by the ray.
RaycastHit floorHit;

// Perform the raycast and if it hits something on the floor layer...
if(Physics.Raycast (camRay, out floorHit, camRayLength, floorMask))
{
// Create a vector from the player to the point on the floor the raycast from the mouse hit.
Vector3 playerToMouse = floorHit.point - transform.position;

// Ensure the vector is entirely along the floor plane.
playerToMouse.y = 0f;

// Create a quaternion (rotation) based on looking down the vector from the player to the mouse.
Quaternion newRotation = Quaternion.LookRotation (playerToMouse);

// Set the player's rotation to this new rotation.
playerRigidbody.MoveRotation (newRotation);
}
}

void Animating (float h, float v)
{
// Create a boolean that is true if either of the input axes is non-zero.
bool walking = h != 0f || v != 0f;

// Tell the animator whether or not the player is walking.
anim.SetBool ("IsWalking", walking);
}
}
1 Like

[quote=“midomady304”, post:3, topic: 587817]
i can’t be turning with mouse please help
[/quote]

Hello Midomady,

your code seems to be correct. Did you set

PlayerRigidBody = GetComponent<Rigidbody>();

in your Awake() function?

Also note, that the easiest way to debug your application is to print your variables and find exactly where the problem is. Try using sample code bellow for your turning function. When you find anything odd in the console (‘null’ being printed etc.) just click on that line. The editor should open your MonoDevelop at the line where the print was done.

Hope that helps you a bit,
rePhat

  void Turning() {
     Ray camRay = Camera.main.ScreenPointToRay(Input.mousePosition);
     Debug.Log("camRay "+camRay);
     RaycastHit floorHit;
    
     if(Physics.Raycast(camRay, out floorHit, camRayLength, floorMask)){
       Vector3 playerToMouse = floorHit.point - transform.position;
       playerToMouse.y = 0f;
       Debug.Log("playerToMouse "+playerToMouse);
      
       Quaternion newRotation = Quaternion.LookRotation(playerToMouse);
       Debug.Log("newRotation "+newRotation);

       PlayerRigidBody.MoveRotation(newRotation);
       Debug.Log("PlayerRigidBody "+PlayerRigidBody);
     }
     else
       Debug.Log("ray didnt hit");
   }
1 Like

[quote]
The black artifacts are most likely bad lightmap data. In Unity 5, Enlighten will try and automatically bake anything marked static, like our environment here. Currently these meshes don't all have valid Lightmap UVs for Enlighten to bake to as the project wasn't initially intended for baking, so you get these weird black areas of overlaps and repeats.

If you go to the project's models folder, select each environment and prop mesh and tick Generate Lightmap UV's in the asset's Inpsector Model tab, wait for Unity to create some valid UV's, then let Enlighten rebake, then you shouldn't see these weird errors anymore (hopefully!)
[/quote]

Hello,

I'm trying to solve this issue to no avail and I'm getting quite desperate. :( Since the Environment is being stored within the assets as a prefab (not a model), I'm not able to access Model tab in my inspector.

Any ideas?

1 Like

@rePhat - did you download the new Unity 5 version of the project and have this problem? very surprised as we've not seen this issue - which version of Unity are you seeing it with? remember we suggest Unity 5.1.1 or greater and the assets are setup for that.

@willgoldstone Well, I've downloaded it a week ago, how old is the new version? I'm using v5.1.1. Also thanks for your quick response ;)

EDIT: I'm downloading new assets, thanks!

[quote=“rePhat”, post:5, topic: 587817]
Hello,

I’m trying to solve this issue to no avail and I’m getting quite desperate. :frowning: Since the Environment is being stored within the assets as a prefab (not a model), I’m not able to access Model tab in my inspector.

Any ideas?
[/quote]

Hello @rePhat ! That’s one of the main issues I wanted to get this update out to solve, so hopefully with the new assets and upgrade guide you should be good to go!

2 Likes

Thank you so much for this! It arrived just at the right time. Loving the learning journey.

I noticed a small mistake in the "04. CREATING ENEMY #1" Section of the PDF. The second paragraph indicates the time 01:20. It should be 11:20. It's obvious once you get to that part but for it could be confusing for some folks who are not paying enough attention.

Again, thanks for the help with this. Here's hoping to see new tutorials soon!

gilkzxc said
i'm sorry for asking too many questions but.... something weird happend after i finished chapter 6 and everything worked fine the backgroung and the scene setting... disappeared... sort of....

I am getting the same problem. Different from the other black scene issue. The background is black at the very start. Firing does provide lighting up the areas. So i guess it is a lightning problem, but appears at it should after you die once. So if i add lightning, i am over compensating after player respawn.

[quote=“dvdhyh”, post:10, topic: 587817]
gilkzxc said
i’m sorry for asking too many questions but… something weird happend after i finished chapter 6 and everything worked fine the backgroung and the scene setting… disappeared… sort of…

I am getting the same problem. Different from the other black scene issue. The background is black at the very start. Firing does provide lighting up the areas. So i guess it is a lightning problem, but appears at it should after you die once. So if i add lightning, i am over compensating after player respawn.
[/quote]

I had that same problem a couple of minutes ago. After some searching on the forums, found out that apparently there’s a bug where the Editor fails to bake the lights after Application.Loadlevel. To fix it, go to Window > Lighting > Lightmaps Tab and uncheck “Auto” to avoid continuous baking and then press Build.

That worked for me!

9 Likes

[quote=“rePhat”, post:4, topic: 587817]
Hello Midomady,

your code seems to be correct. Did you set

PlayerRigidBody = GetComponent<Rigidbody>();

in your Awake() function?

Also note, that the easiest way to debug your application is to print your variables and find exactly where the problem is. Try using sample code bellow for your turning function. When you find anything odd in the console (‘null’ being printed etc.) just click on that line. The editor should open your MonoDevelop at the line where the print was done.

Hope that helps you a bit,
rePhat

  void Turning() {
     Ray camRay = Camera.main.ScreenPointToRay(Input.mousePosition);
     Debug.Log("camRay "+camRay);
     RaycastHit floorHit;
   
     if(Physics.Raycast(camRay, out floorHit, camRayLength, floorMask)){
       Vector3 playerToMouse = floorHit.point - transform.position;
       playerToMouse.y = 0f;
       Debug.Log("playerToMouse "+playerToMouse);
     
       Quaternion newRotation = Quaternion.LookRotation(playerToMouse);
       Debug.Log("newRotation "+newRotation);

       PlayerRigidBody.MoveRotation(newRotation);
       Debug.Log("PlayerRigidBody "+PlayerRigidBody);
     }
     else
       Debug.Log("ray didnt hit");
   }

[/quote]
The problem is everything is ok !!! look at this ((((
2188578--145172--upload_2015-7-4_10-19-22.jpg

@midomady304 I'm seeing just two variables and its not obvious which are theese.. Its generally good to print the same text, like your variable name in order to avoid confusion. The most important one for this particular task is your RigidBody., and therefore I have to ask you again, did u set your reference in the Awake() function?

do you mean this !

void Awake ()
{

floorMask = LayerMask.GetMask ("Floor");
anim = GetComponent <Animator> ();
playerRigidbody = GetComponent <Rigidbody> ();
}

Yes, exactly this. Can you upload your project somewhere, so I can take a closer look? It may be of help for other people having the same problem :)

i upload the project here
https://drive.google.com/file/d/0B-Ovmu9fEsURTXJyLVhZVFYyelU/view?usp=sharing

1 Like

the problem is when i started make this project 1st time everything was ok !!!!!
now i tried and i have this problem (((((((

I understand this is the new thread.

I would like to point out a possible issue or bug in the C# script for "Creating Enemy #1" of the tutorial.

http://unity3d.com/learn/tutorials/projects/survival-shooter/enemy-one

This person's post from the old closed thread helped me get it working where the enemy just moved to the center of the level and stayed there moving and did not follow the player.

http://forum.unity3d.com/threads/survival-shooter-q-a.313934/page-2#post-2101162

So I also changed (Line 15) of that script from

player = GameObject.FindGameObjectWithTag ("Player").transform;

to

player = GameObject.Find ("Player").transform;

and it works, the enemy follows the player character

I also notice that the summary tooltip description in MonoDevelop-Unity for Find has a description of what it does,
"Finds a game object by name and returns it" but the FindGameObjectWithTag does not have a summary tooltip

I have not yet made a full game using Tags all the way through in code but this would be a problem. Perhaps I need to work more with Tags in code to see them working. If I encounter anymore of these issues I will let Unity know somehow.

8 Likes

@jaimemh - thanks we've now updated the PDF, appreciate the help.
@uni00 - thanks for pointing this out but not sure why it would not be working with tag, as the Player tag a) always exists in Unity projects and b) should be assigned to the player character during the tutorial.

[quote]
@uni00 - thanks for pointing this out but not sure why it would not be working with tag, as the Player tag a) always exists in Unity projects and b) should be assigned to the player character during the tutorial.
[/quote]

EDIT: I have solved my problem with FindGameObjectWithTag ("Player")

I AM USING UNITY 5.1.1f1.

I WAS NOT USING THE CORRECT ASSET PACKAGE FOR UNITY 5.1 WHEN I CREATED THE PROJECT.

SO I HAVE CREATED A NEW PROJECT USING THE ASSET PACKAGE CALLED "Unity 5 Survival Shooter"

(THE PACKAGE I WAS USING BEFORE WAS CALLED "Survival Shooter")

Thank you for the help.