Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Survival Shooter Q&A

Discussion in 'Community Learning & Teaching' started by willgoldstone, Jul 3, 2015.

  1. Tradge20

    Tradge20

    Joined:
    Feb 9, 2018
    Posts:
    4
    I'd like to see that too
     
  2. Tradge20

    Tradge20

    Joined:
    Feb 9, 2018
    Posts:
    4
    I'm getting
    NullReferenceException: Object reference not set to an instance of an object
    PlayerHealth.Update () (at Assets/Scripts/Player/PlayerHealth.cs:44)

    44. damageImage.color = Color.Lerp (damageImage.color, Color.clear, flashSpeed * Time.deltaTime);

    I have no idea what is wrong please help
     
  3. Superdude2411

    Superdude2411

    Joined:
    Feb 16, 2018
    Posts:
    1
    What do you mean by "in the root" of the assets folder? I tried to make a normal folder inside the assets folder and save the scene in that, but it said that the scene wasn't in the assets folder, even though it was in a folder that was in the assets folder. How do you make a scenes folder that's "in the root" of the assets folder?

    I'm on Windows if that's part of the problem.
     
  4. PjElliott

    PjElliott

    Joined:
    Feb 12, 2018
    Posts:
    2
    I've been looking for the solution to this problem myself. Obviously my code is correct because it's already written! For some reason however the friggin Zombunny won't attack and my health never budges when he is bumping and grinding on me. I have seen others ask this exact question and it seems like people are ignoring the question no matter who asks it or how. What the hell?! I'M SICK OF BEING STUCK!

    Update: Upon further tedious and pain staking inspection, It's been all day for cripes sakes(!)......I may have forgotten to select "IsTrigger" on the sphere collider on the zombunny......WHAT?!...:oops:...At least there is a possible solution for others who may have the same problem...I apologize for yelling...IT WAS JUST SO FRUSTERATING!:mad:...:eek:breath:eek:breath:eek:...i need some chamomile tea.
     
    Last edited: Feb 22, 2018
  5. moskus4

    moskus4

    Joined:
    Feb 22, 2018
    Posts:
    1
    I have the same code as the source, but I get an error after declaring the variable
    float camRayLength = 100f;
    It says that "Method must have a return type".
    How do I fix this?
     
  6. PjElliott

    PjElliott

    Joined:
    Feb 12, 2018
    Posts:
    2
    If I could help I would need to see the entire code. Did you perhaps add anything to it? That's just declaring a variable named camRayLength and setting it's value. there's no method to look at. a method look like:

    void SomeName()
    {

    }
     
  7. rukyimza66

    rukyimza66

    Joined:
    Feb 14, 2018
    Posts:
    1
    Player will have another player, delete the script at the Player below.
    upload_2018-3-5_18-53-48.png
     
  8. Kinshuk23

    Kinshuk23

    Joined:
    Mar 11, 2018
    Posts:
    1
    Sir,
    I recently started learning unity so I started with this project and I am having problems with the spawning of zombear and Hellephant .
    These two enemies are not following the player to attack i have checked all scripts for these two and they are written write .
    Currently i am on unity 5.6.0 so please guide me through this problem.
    All features except this are working properly.
     
  9. Galapads

    Galapads

    Joined:
    Mar 20, 2018
    Posts:
    1
    I would also be interested in an answer for your question... I will continue and see what happens however!
     
  10. makaka-org

    makaka-org

    Joined:
    Dec 1, 2013
    Posts:
    1,004
    Hi, Guys!

    I noticed that the tutorial needs some optimizations in code & UI to publishing for mobile platforms.

    I continue experiments with AR and I used this tutorial for implementing AR FPS project.
    So I implemented those optimizations together with AR.

    ☄ AR Survival Shooter

    ☄ Get it on Unity Asset Store: https://goo.gl/Wn8fiD

     
    Brittonian_Embassy likes this.
  11. APPSTATION

    APPSTATION

    Joined:
    Feb 28, 2018
    Posts:
    2
    Hello I'm having an issue just after 9 it seems to me when I add the zombear and hellephant into the enemy manager things start going crazy. I didnt have prefabs for my zombears and hellephants in my prefabs folder but when i searched the asset I found them the zombear has an additional volume handler script but im not sure if this will affect it! ill put up a few screen shots any one had this issue? Or have any idea on where to look to fix this issue? Screenshot (87).png Screenshot (88).png Screenshot (89).png
     

    Attached Files:

    Last edited: Apr 6, 2018
  12. shubhamshetkar25

    shubhamshetkar25

    Joined:
    Feb 4, 2017
    Posts:
    21
    i am experimenting with Unity Survival Shooter project.
    i am getting this error when i kill enemy.

    Error on line 33 here


    NullReferenceException: Object reference not set to an instance of an object
    CompleteProject.EnemyHealth.TakeDamage (Int32 amount, Vector3 hitPoint) (at Assets/_Complete-Game/Scripts/Enemy/EnemyHealth.cs:76)
    CompleteProject.PlayerShooting.Shoot () (at Assets/_Complete-Game/Scripts/Player/PlayerShooting.cs:111)
    CompleteProject.PlayerShooting.Update () (at Assets/_Complete-Game/Scripts/Player/PlayerShooting.cs:49)


    this is my Enemy Health Script :

    Code (CSharp):
    1. public class EnemyHealth : MonoBehaviour
    2.     {
    3.  
    4.         EnemyManager enemyManager;
    5.         int enemyHealth;
    6.  
    7.        
    8.         public void TakeDamage (int amount, Vector3 hitPoint)
    9.         {
    10.             // If the enemy is dead...
    11.             if(isDead)
    12.                 // ... no need to take damage so exit the function.
    13.                 return;
    14.  
    15.             // Play the hurt sound effect.
    16.             enemyAudio.Play ();
    17.  
    18.             // Reduce the current health by the amount of damage sustained.
    19.             currentHealth -= amount;
    20.            
    21.             // Set the position of the particle system to where the hit was sustained.
    22.             hitParticles.transform.position = hitPoint;
    23.  
    24.             // And play the particles.
    25.             hitParticles.Play();
    26.  
    27.             // If the current health is less than or equal to zero...
    28.             if(currentHealth <= 0)
    29.             {
    30.                 // ... the enemy is dead.
    31.                 Death ();
    32.  
    33.                 enemyManager.enemiesKilled++;
    34.                 if (enemyManager.enemiesKilled >= enemyManager.maxEnemyCount)
    35.                     //Change Scene
    36.                     SceneManager.LoadScene("start");[/B]
    37.  
    38. [B]        }
    39.     }
    40. }
     
    Last edited: Apr 6, 2018
  13. Armitgae

    Armitgae

    Joined:
    Mar 28, 2018
    Posts:
    3
    Hello everyone! I'm currently on 07 : Harming enemies. Everything is going great, my gun shoots. I can see the light my shots collide with the enemy then... nothing. My shots will collide with the enemy and the environment, but he wont take damage and the particle effect doesn't show. I don't know what the problem is, all I know is that its a logic error. Any help will be greatly appreciated.
     
  14. Armitgae

    Armitgae

    Joined:
    Mar 28, 2018
    Posts:
    3
    Hello everyone. I'm currently working on this project, going through without any problems. But then I hit a brick wall. On step 7, harming the enemy, i'm stumped. My gun shoots, it collides with everything including the enemy. But the enemy doesn't die, I shot him hundreds of times and nothing happens. I haven't changed anything in the scripts (the scripts being enemyHealth and playerShooting). Please help!
     
  15. pikachu_98123

    pikachu_98123

    Joined:
    Apr 18, 2018
    Posts:
    1
    Hi. i am a newbie, now, this assets for survival shooter game in assests website is no longer available, so i can find it to make this game. Have anyone had this assests or completed this game, please give me :(
     
  16. picklesimers

    picklesimers

    Joined:
    Apr 24, 2018
    Posts:
    1
    I am having trouble with the 1st zoombunny dying, it will take damage and die one time. Then if you try to test the game again it will not die. I have to delete the scripts from the folder, download them again and reassign them again to get it ot work, but then it will run only once again. Any suggestions?
     
    makaka-org likes this.
  17. makaka-org

    makaka-org

    Joined:
    Dec 1, 2013
    Posts:
    1,004
    ☄️ VR SURVIVAL SHOOTER

    Hi, friend!

    I have released VR version of the asset.
    Available on the Unity Asset Store (Docs).

     
  18. jackgrossi

    jackgrossi

    Joined:
    Apr 28, 2018
    Posts:
    1
    how do i get the assets?
     
  19. weitingtw

    weitingtw

    Joined:
    Apr 26, 2018
    Posts:
    1
    I'm just wondering where do we restrict the player's movement not to go beyond the surface?
     
  20. imcheney

    imcheney

    Joined:
    Oct 11, 2017
    Posts:
    3

    I solved your problem in Unity2017 by change the if statement to
    "Physics.Raycast (camRay, out floorHit, camRayLength)"
    i.e. in the new Unity API, somehow we don't need to input the floorMask to Physics.Raycast function anymore.

    So, issue closed :)
     
    SharkB likes this.
  21. BrewNCode

    BrewNCode

    Joined:
    Feb 17, 2017
    Posts:
    372
    I'm sorry if this is a repeated question, but. for Unity 2017, what are the properties of the bake section of the Navmesh for the Zoembunny. I can't find the height and width innacuracy %.
     
  22. skyemagethe3rd

    skyemagethe3rd

    Joined:
    May 15, 2018
    Posts:
    6
    So I just downloaded Unity 2018.1 and am taking the Shooter Tutorial trying to get my bearings and ran into a snag...
    troubleshoot Shooter Tutorial Ep 2.jpg

    Apparently there are multiple things wrong with my coding even though I thought I followed every instruction to the T as well as there is a problem with UV Overlap... I don't know the first thing to fixing this so I desperately need help as I'm only on the 2nd video out of 10 and obviously I suck at coding. Can someone please take a look at this and my coding and tell me what's wrong?

    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class PlayerMovement : MonoBehaviour
    4. {
    5.     public float speed = 6f;
    6.  
    7.     vector3 movement;
    8.     Animator anim;
    9.     Rigidbody playerRigidbody;
    10.     int floorMask;
    11.     float camRayLength = 100f;
    12.  
    13.     void Awake ()
    14.     {
    15.         floorMask = LayerMask.GetMask("Floor");
    16.         anim = GetComponent<Animator>();
    17.         playerRigidbody = GetComponent<playerRigidbody>();
    18.     }
    19.  
    20.     void FixedUpdate()
    21.     {
    22.         float h = Input.GetAxisRaw("Horizontal")
    23.         float v = Input.GetAxisRaw ("Vertical")
    24.  
    25.             Move(h, v);
    26.         Turning();
    27.         Animating(h, v);
    28.  
    29.     }
    30.  
    31.     void Move (float h, float v)
    32.     {
    33.         movement.Set(h, 0f, v);
    34.  
    35.         movement = movement.normalized * speed * Time.deltaTime;
    36.  
    37.         playerRigidbody.MovePosition(transform.position + movement);
    38.     }
    39.  
    40.     void Turning()
    41.         {
    42.         Ray camRay = Camera.main.ScreenPointToRay(Input.mousePosition);
    43.  
    44.         RaycastHit floorHit;
    45.  
    46.         if(Physics.Raycast (camRay, out floorHit, camRayLength, floorMask))
    47.         {
    48.             vector3 playerToMouse = floorHit.point - transform.position;
    49.             playerToMouse.y = 0f;
    50.  
    51.             quaternion newRotation = quaternion.LookRotation(playerToMouse);
    52.             playerRigidbody.MoveRotation(newRotation);
    53.         }
    54.     }
    55.  
    56.     void Animating(float h, float v)
    57.     {
    58.         bool walking = h != 0f || v != 0f;
    59.         anim.SetBool("IsWalking", walking);
    60.     }
    61. }
     
  23. unity_FFrCoOjtlloVsA

    unity_FFrCoOjtlloVsA

    Joined:
    May 29, 2018
    Posts:
    2
    i got the UV overlap message too but it didn't cause any problems in running the program. however your two float variables h and v when you initialized them you forgot to put the semi-colon ";" at the end. also you put <playerRigidbody> where it should have just been <Rigidbody> I would also suggest aligning Move(h, v); with the two below it (more for looks than anything else). both places you have "quaternion" need to be capitalized "Quaternion". That's all the mistakes that i see with your code here's mine if you need a reference it worked and ran for me so it should be good. Hope this helped.

    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class PlayerMovement : MonoBehaviour
    4. {
    5.     public float speed = 6f;
    6.  
    7.     Vector3 movement;
    8.     Animator anim;
    9.     Rigidbody playerRigidbody;
    10.     int floorMask;
    11.     float camRayLength = 100f;
    12.  
    13.     private void Awake()
    14.     {
    15.         floorMask = LayerMask.GetMask("Floor");
    16.         anim = GetComponent<Animator>();
    17.         playerRigidbody = GetComponent<Rigidbody>();
    18.     }
    19.  
    20.     private void FixedUpdate()
    21.     {
    22.         float h = Input.GetAxisRaw("Horizontal");
    23.         float v = Input.GetAxisRaw("Vertical");
    24.  
    25.         Move(h, v);
    26.         Turning();
    27.         Animating(h, v);
    28.     }
    29.  
    30.     void Move(float h, float v)
    31.     {
    32.         movement.Set(h, 0f, v);
    33.         movement = movement.normalized * speed * Time.deltaTime;
    34.  
    35.         playerRigidbody.MovePosition(transform.position + movement);
    36.     }
    37.  
    38.     void Turning()
    39.     {
    40.         Ray camRay = Camera.main.ScreenPointToRay(Input.mousePosition);
    41.  
    42.         RaycastHit floorHit;
    43.  
    44.         if(Physics.Raycast(camRay, out floorHit, camRayLength, floorMask))
    45.         {
    46.             Vector3 playerToMouse = floorHit.point - transform.position;
    47.             playerToMouse.y = 0f;
    48.  
    49.             Quaternion newRotation = Quaternion.LookRotation(playerToMouse);
    50.             playerRigidbody.MoveRotation(newRotation);
    51.         }
    52.     }
    53.  
    54.     void Animating(float h, float v)
    55.     {
    56.         bool walking = h != 0f || v != 0f;
    57.         anim.SetBool("IsWalking", walking);
    58.     }
    59. }
    60.  
     
  24. unity_FFrCoOjtlloVsA

    unity_FFrCoOjtlloVsA

    Joined:
    May 29, 2018
    Posts:
    2
    I just fixed the if statement to fix a different problem I was having as well. The "floorMask" should not be in the if statement idk why exactly but with that in there it wouldnt allow me to turn using the mouse. Again hope this helps good luck.
     
    StreamOfMaya likes this.
  25. mdolphin

    mdolphin

    Joined:
    Jun 20, 2018
    Posts:
    1
    I'm new to Unity, and after I finished some other basic Tutorials, I now try this Survival Shooter Tutorial. My Unity Version is 2018.1.4f1

    I've just finished the second Video of the Tutorial Series.

    Problem: Whenever I load this project into the Editor Unity instantly starts the "Baking" process, and that takes nearly an hour, while consuming 100% CPU. Whenever I change anything in the Scene View, Baking starts again. Therefore I can't really progress with this Tutorial, and I have no idea what to switch off or change in the project settings, so that either Baking may be much faster, or just runs when I explicitely tell Unity to start the Baking Process.
     
  26. John553

    John553

    Joined:
    Jun 23, 2018
    Posts:
    2
    my walking animation wont work and i dont know why, here is my code

    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class PlayerMovement : MonoBehaviour
    4. {
    5.     public float speed = 6f;
    6.  
    7.     Vector3 movement;
    8.     Animator anim;
    9.     Rigidbody playerRigidbody;
    10.     int floorMask;
    11.     float camRaylenght = 100f;
    12.  
    13.     void Awake()
    14.     {
    15.         floorMask = LayerMask.GetMask("Floor");
    16.         anim = GetComponent<Animator>();
    17.         playerRigidbody = GetComponent<Rigidbody>();
    18.     }
    19.  
    20.     void FixedUpdate()
    21.     {
    22.         float h = Input.GetAxisRaw("Horizontal");
    23.         float v = Input.GetAxisRaw("Vertical");
    24.  
    25.         Move (h, v);
    26.         Turning ();
    27.         Animating (h, v);
    28.  
    29.     }
    30.     void Move(float h, float v)
    31.  
    32.     {
    33.         movement.Set(h, 0f, v);
    34.  
    35.         movement = movement.normalized * speed * Time.deltaTime;
    36.  
    37.         playerRigidbody.MovePosition(transform.position + movement);
    38.     }
    39.     void Turning()
    40.     {
    41.         Ray camRay = Camera.main.ScreenPointToRay(Input.mousePosition);
    42.  
    43.         RaycastHit floorHit;
    44.  
    45.         if (Physics.Raycast (camRay, out floorHit, camRaylenght, floorMask))
    46.         {
    47.             Vector3 playerToMouse = floorHit.point - transform.position;
    48.             playerToMouse.y = 0f;
    49.  
    50.             Quaternion newRotation = Quaternion.LookRotation(playerToMouse);
    51.             playerRigidbody.MoveRotation (newRotation);
    52.         }
    53.     }
    54.     void Animating(float h, float v)
    55.     {
    56.         bool walking = h != 0f || v != 0f;
    57.         anim.SetBool("IsWalking", walking);
    58.     }
    59.      
    60.    
    61. }
    62.  
     
  27. AwsomeRod

    AwsomeRod

    Joined:
    Oct 13, 2012
    Posts:
    3
    I get a problem with the Mesh. My enemies spawn in the right place but they won't walk. They do the animation but do not walk.
    "Failed to create agent because there is no valid NavMesh
    UnityEngine.Object:Instantiate(GameObject, Vector3, Quanternion)"
    ""SetDestination" can only be called on an active agent that has been placed on a NavMesh.
    UnityEngine.AI.NavMeshAgent:SetDestination(Vector3)"
     
  28. Deleted User

    Deleted User

    Guest

    Hello all!!!
    I had the issue that lighting is getting turned off on restarting my game again. I am running on 2018.1.3f1. This is how I solved the issue.
    Go to 'Windows/Lighting/Settings/Object Maps'. Uncheck the 'Auto Generate' checkbox and in the drop-down menu located by its side, select 'General Lighting'. Now close the 'Settings' dialog box and run the game. That should work fine.
     
  29. Psyberion

    Psyberion

    Joined:
    Jun 19, 2018
    Posts:
    2
    Hi, I also didn't get the Zombear and Hellephant prefabs, but created them from the models. The Zombear works fine, the only issue I have with the Hellephant is that it won't die. I created the HellephantAOC, dragged on the Idle, Move and Death animations from the model, and dropped the HelephantAOC into the Controller on the Animator component. i can shoot the Hellephant over and over again, it makes the hurt sound and the health goes below 0. Since the HellephantAOC has the controller set to EnemyAC I would expect it to act in the same way as the Zombear and Zombunny. I even tried setting the isDead bool in the EnemyHealth script to public so I could see it in the inspector whilst running, I didn't see it trigger and I tried ticking it to see if it triggered the death but to no avail. The Hellephant does stop moving though, so it's disabling the nav in the EnemyMovement script because the enemy health is below 0. But it continues to play the Move animation.
     
  30. Psyberion

    Psyberion

    Joined:
    Jun 19, 2018
    Posts:
    2
    Fixed it. Hadn't noticed there was an error occurring each time they hit the Death function. This was because I hadn't added the HitParticles to the Hellephant, so in the EnemyHealth script TakeDamage function, it wasn't flagged as isDead, it played the hurt audio, reduced the health, then the error occurred on setting the hitParticles.transform.position because it hadn't found the hit particles. After adding the hit particles the error didn't occur and it worked.
     
    Naiskick likes this.
  31. OG_Games

    OG_Games

    Joined:
    Jul 5, 2018
    Posts:
    1
    I am having troubles getting the animator override controller working. I have completed the tutorial and everything is working well except for the fact that the hellaphant won't play any of it's animations. It will follow the player and attack but it just slides around the scene and when it is killed it simply disappears. I have created a HellaphantAOC to attach to the hellaphant prefab and the EnemyAC is placed into it. I have placed all of the hellaphant's clips found in the "Model" folder into the override column but still none of the animations will play. The hellaphant prefab has the same components as the other enemy prefabs and it behaves the same as the other enemies apart from the animator being completely inert.

    If anyone has any clue as to how to fix this please fill me in because I've stayed up until 3am two nights in a row trying to fix this simple problem.

    If a screenshot will help ask and I'll post it because right now I cant think of anything that would assist you.

    Thanks!!
     
  32. rileyjacksonhockey

    rileyjacksonhockey

    Joined:
    Jul 26, 2018
    Posts:
    1
    Running the _complete_game project file is giving me an "all compiler errors have be fixed before entering play mode". Assets and Unity are fully updated. Once I figure out how to get it to play I wish to make an original music score for the game. All help is appreciated. :)
     
  33. Deleted User

    Deleted User

    Guest

    you can view your errors in the console... just check them out and try correcting...
     
  34. Deleted User

    Deleted User

    Guest

    I am stuck with LINE RENDERER... Working on 2018.2... No idea how to set the with of the line renderer on this newly updated renderer component... Also, my line is coming embedded into the floor... How to solve these??
     

    Attached Files:

  35. Charliea835

    Charliea835

    Joined:
    Jul 27, 2018
    Posts:
    2
    hey man, I was stuck on the line renderer too. if you look where it says Width and the box under it saying 1.0, you can actually click into that and change the width there. As for the line being embedded in the floor I'm not sure, did you add the line renderer to the gun barrel end?

    this is the inspector for my gunbarrell end. hope this helps
     

    Attached Files:

  36. Charliea835

    Charliea835

    Joined:
    Jul 27, 2018
    Posts:
    2
    Hi everyone, I am having an issue with this survival shooter. I have reached the end of it but have two issues, firstly, when the main character dies, even without the game over manager script not selected, the game restarts on death anyway. I don't know how to stop this. also, the game over animation with the script attached doesn't stay for long
     
    yotrica likes this.
  37. m0rose

    m0rose

    Joined:
    Aug 10, 2018
    Posts:
    1
    Whenever I press 'play' in Unity (not finished, just watched 03), the camera and player freeze for about a second. Then, the camera jolts to a much farther-away position. It doesn't follow the player. Looking in the inspector, the camera's x and z coords sometimes shift a bit higher or lower, but never much more than one unit. When this happens, the camera doesn't move even a bit. I watched the video twice over already; I have no idea what to do.
     
  38. BGR521

    BGR521

    Joined:
    Aug 10, 2018
    Posts:
    1
    I'm on part 4 of the tutorial, and i cant seem to get the zombunny to track my player. I followed the video, doing everything it told me, not altering the script, and created the nav mesh to the best of my ability (im missing the inaccuracy options, so that could be the reason, although i doubt it). No matter what i try, the enemy just runs in place and refuses to track my player. If anyone knows a fix to this, i would highly appreciate it.
     

    Attached Files:

    Last edited: Aug 14, 2018
  39. magsuplays

    magsuplays

    Joined:
    Aug 21, 2018
    Posts:
    1
    So I couldn't find the answer to this here in this forum post and though someone else might encounter this problem too. I am using Unity version 2018.2.4f1.

    I was on the "Phase 02 Player Character". I created the project with the updated assets and went trough the tutorial no problem untill after editing the script my animations weren't working correctly and I was getting this error:

    NullReferenceException: Object reference not set to an instance of an object
    PlayerMovement.Turning () (at Assets/Scripts/Player/PlayerMovement.cs:55)
    PlayerMovement.FixedUpdate () (at Assets/Scripts/Player/PlayerMovement.cs:34)

    Which (as the error states) tells that it can't find an object to reference to. In this case the object is the Camera which we are trying to reference to on this line:

    Ray camRay = Camera.main.ScreenPointToRay(Input.mousePosition);

    After a while of banging my head against the wall and searching trough google I took a look at the API Documentation and something in the docs (https://docs.unity3d.com/ScriptReference/Camera-main.html) caught my eye. In the documentation it states that the Camera object's method "main" searches for "The first enabled camera tagged 'MainCamera'".

    The problem was that my "Main Camera" object in the Unity Hierarchy tab wasn't tagged as "MainCamera" but was "Untagged". After changing the "Untagged" to "MainCamera" (just like you did tag the "Player" object as "Player" earlier in the same tutorial) everything was working just fine.
     
  40. tongqushengshou

    tongqushengshou

    Joined:
    Aug 22, 2018
    Posts:
    1
    Nice,it helps me solve this problem.Thanks!
     
  41. Arno1975

    Arno1975

    Joined:
    Aug 14, 2013
    Posts:
    43

    see the solution of magsuplays...two posts up...had the same problem..now my animation runs but my ray isn't hitting anything for turning..
     
  42. Arno1975

    Arno1975

    Joined:
    Aug 14, 2013
    Posts:
    43
    Unity 2018.2 - chapter 2 player - problem turning

    My player won't turn. Well it does turn when i point at a toy that is laying around (when i remove the floormask from the if statement) on the floor, but not when my ray hits the floor.
    Well my debug says i do have a ray but it isn't hitting anything.
    My quad has the layer Floor (checked capitols), my maincamera has the tag maincamera envoirement has tag shootable.
    my quad has the mesh filter and the mesh collider

    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class PlayerMovement : MonoBehaviour
    4. {
    5.     public float speed = 6f;            // The speed that the player will move at.
    6.  
    7.     Vector3 movement;                   // The vector to store the direction of the player's movement.
    8.     Animator anim;                      // Reference to the animator component.
    9.     Rigidbody playerRigidbody;          // Reference to the player's rigidbody.
    10.     int floorMask;                      // A layer mask so that a ray can be cast just at gameobjects on the floor layer.
    11.     float camRayLength = 1000f;          // The length of the ray from the camera into the scene.
    12.  
    13.     void Awake()
    14.     {
    15.         // Create a layer mask for the floor layer.
    16.         floorMask = LayerMask.GetMask("Floor");
    17.  
    18.         // Set up references.
    19.         anim = GetComponent<Animator>();
    20.         playerRigidbody = GetComponent<Rigidbody>();
    21.     }
    22.  
    23.  
    24.     void FixedUpdate()
    25.     {
    26.         // Store the input axes.
    27.         float h = Input.GetAxisRaw("Horizontal");
    28.         float v = Input.GetAxisRaw("Vertical");
    29.  
    30.         // Move the player around the scene.
    31.         Move(h, v);
    32.  
    33.         // Turn the player to face the mouse cursor.
    34.         Turning();
    35.  
    36.         // Animate the player.
    37.         Animating(h, v);
    38.     }
    39.  
    40.     void Move(float h, float v)
    41.     {
    42.         // Set the movement vector based on the axis input.
    43.         movement.Set(h, 0f, v);
    44.  
    45.         // Normalise the movement vector and make it proportional to the speed per second.
    46.         movement = movement.normalized * speed * Time.deltaTime;
    47.  
    48.         // Move the player to it's current position plus the movement.
    49.         playerRigidbody.MovePosition(transform.position + movement);
    50.     }
    51.  
    52.     void Turning()
    53.     {
    54.         // Create a ray from the mouse cursor on screen in the direction of the camera.
    55.         Ray camRay = Camera.main.ScreenPointToRay(Input.mousePosition);
    56.  
    57.         Debug.Log("camRay " + camRay);
    58.  
    59.         // Create a RaycastHit variable to store information about what was hit by the ray.
    60.         RaycastHit floorHit;
    61.  
    62.         // Perform the raycast and if it hits something on the floor layer...
    63.         if (Physics.Raycast(camRay, out floorHit, camRayLength, floorMask))
    64.         //if (Physics.Raycast (camRay, out floorHit, camRayLength))
    65.         {
    66.             // Create a vector from the player to the point on the floor the raycast from the mouse hit.
    67.             Vector3 playerToMouse = floorHit.point - transform.position;
    68.  
    69.             // Ensure the vector is entirely along the floor plane.
    70.             playerToMouse.y = 0f;
    71.             Debug.Log("playerToMouse " + playerToMouse);
    72.  
    73.             // Create a quaternion (rotation) based on looking down the vector from the player to the mouse.
    74.             Quaternion newRotation = Quaternion.LookRotation(playerToMouse);
    75.             Debug.Log("newRotation " + newRotation);
    76.  
    77.             // Set the player's rotation to this new rotation.
    78.             playerRigidbody.MoveRotation(newRotation);
    79.             Debug.Log("playerRigidBody " + playerRigidbody);
    80.         }
    81.         else
    82.             Debug.Log("ray didnt hit");
    83.     }
    84.  
    85.     void Animating(float h, float v)
    86.     {
    87.         // Create a boolean that is true if either of the input axes is non-zero.
    88.         bool walking = h != 0f || v != 0f;
    89.         Debug.Log(h + v);
    90.  
    91.         // Tell the animator whether or not the player is walking.
    92.         anim.SetBool("IsWalking", walking);
    93.     }
    94. }
    please help i wan't to make this game with my son and get him into Unity


    so when i remove the floormask from the if statement..and put a collider at the base of the floor, then it works..but i don't understand why the original doesn't work with the floormask being called...
     
    Last edited: Aug 28, 2018
  43. hetulsheth

    hetulsheth

    Joined:
    Aug 28, 2018
    Posts:
    1



    Did your problem got solved??
     
  44. winxalex

    winxalex

    Joined:
    Jun 29, 2014
    Posts:
    166
    For those with no code experience and of for programmers we made series of videos.


     
  45. yurigligoric

    yurigligoric

    Joined:
    Sep 8, 2018
    Posts:
    2
    Hi,

    I encountered a problem with lesson Creating Enemy #1.. i followed the instruction to the dot before I baked the navmesh. But I got an error and tried to adjust the setting based on the suggestion of Unity. I adjusted the max slope to 13.9 but I cannot re-bake the navmesh again. If I stick with 45, there's an error about step height conflict. I'm using Unity 2018.2,6f1 version...

    Right now the error in compiler is: There are 12 objects in the Scene with overlapping..."

    Another problem is the script EnemyMovement seemed global or I don't know. I created a new script file to follow the instruction but would get error. .

    Thanks. :)
     
  46. pablothetacoman1812

    pablothetacoman1812

    Joined:
    Sep 25, 2017
    Posts:
    5
    hello everyone, im on stage six of the tutorial and rather than my zombunny running up to and attacking the player, he just stands a few feet away while performing the walking animation. he will still follow me around but will never get close enough to do damage unless i walk closer to him. I think the problem is the navmesh is treated like a solid object as the distance the bunny stops at is the same as the navmesh's radius. If someone could point me in the right direction that would be amazing
     
  47. yurigligoric

    yurigligoric

    Joined:
    Sep 8, 2018
    Posts:
    2
    I'm stuck now in this issue...
     
  48. JC_LEON

    JC_LEON

    Joined:
    May 20, 2014
    Posts:
    518
    hi i dont know if this argument was discussed before but
    IS THERE A way to add an attack anmation when enemies are attacking the player^???
     
  49. BrewNCode

    BrewNCode

    Joined:
    Feb 17, 2017
    Posts:
    372
    Maybe was already here, but at the moment of killing the Zoembunny, the Death audio clip sounds, but the zoembunny won't trigger the Death animation and it won't sink.

    The Death animation is set to Any state and the parameter is already set on the transition. I don't know what to do :c

    EDIT: Problem soved. In code the animation was called "Dead" but I mamed the parameter to "Death". Changing the name of the parameter solved the issue.
     
    Last edited: Oct 7, 2018
  50. drandy007

    drandy007

    Joined:
    Mar 11, 2018
    Posts:
    9
    How do I fix my nav mesh so, it looks the same as video (13:25)?
    Capture.JPG
    Capture2.JPG