Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Official TANKS! Tutorial Q&A

Discussion in 'Community Learning & Teaching' started by willgoldstone, Sep 21, 2015.

  1. ntiTobias

    ntiTobias

    Joined:
    Mar 31, 2017
    Posts:
    1
    I'm trying to make a menu for the Tanks!-game. I can't get the UI work in this project though. I can't get the buttons respond. Is there some setting made to disable ordinary UI-functions? How do I do to make a menu for this project?
     
    Last edited: Apr 6, 2017
  2. Darky_lucera

    Darky_lucera

    Joined:
    Mar 24, 2015
    Posts:
    1
    Is there some patch to make the same 'trail particle' effect with the current unity version (5.6)?
     
    Last edited: Apr 13, 2017
  3. Thesam19

    Thesam19

    Joined:
    Feb 2, 2017
    Posts:
    1
    How to display the player name on a tank!! & how to display the result winner with player name!!
    I have taken 2 input fields to store the names in pref file
     
  4. olyvatwist

    olyvatwist

    Joined:
    Dec 8, 2015
    Posts:
    2
    Importing the tank asset into unity 5.5 give me redish color for the metalic models..
    Little help please.
    metal 2.PNG
    suppose to be gold

    metal.PNG
     
  5. olyvatwist

    olyvatwist

    Joined:
    Dec 8, 2015
    Posts:
    2
    Figured it out..
    By turning of reflections in the Forward Rendering Options in the Standard Shader.
     
  6. ix84gaming

    ix84gaming

    Joined:
    Apr 16, 2017
    Posts:
    2
    When I try to play the project, the tank will barely move. I have checked and Visual Studios says the code is fine. Can you help?
     
  7. Armouredgamer

    Armouredgamer

    Joined:
    May 2, 2017
    Posts:
    1
    Hi!
    I appreciate the tutorial, It's what I've been using in my programming class. I've been trying to add another player, which I can do, they spawn in, have an new spawn and color. If I end the round, they even pop up at the score screen!
    My only issue with player three, well, is that I'm unsure as to how to give them controls. If I could get some help, it'd be heavily appreciated! :)
     
  8. ix84gaming

    ix84gaming

    Joined:
    Apr 16, 2017
    Posts:
    2
    Go into the controls menu and add more controls
     
  9. thevinegru

    thevinegru

    Joined:
    Mar 24, 2017
    Posts:
    2
    I'm getting the exact same problem. The tutorial is using an LDR color picker and the color picker on that menu is HDR. I can't figure it out at all.
     
  10. thevinegru

    thevinegru

    Joined:
    Mar 24, 2017
    Posts:
    2
    Since updating to 5.6, this is the error I get.

    "Lighting data asset ‘LightingData’ is incompatible with the current Unity version. Please use Generate Lighting to rebuild the lighting data. Realtime Global Illumination cannot be used until the lighting data is rebuilt."

    Any suggestions?
     
  11. RobH99

    RobH99

    Joined:
    May 14, 2017
    Posts:
    5
    I finished the tutorial through Phase 7: Game Managers. I'm getting the following compile error:
    MissingComponentException: There is no 'AudioSource' attached to the "TankExplosion(Clone)" game object, but a script is trying to access it.
    You probably need to add a AudioSource to the game object "TankExplosion(Clone)". Or your script needs to check if the component is attached before using it.
    UnityEngine.AudioSource.Play () (at C:/buildslave/unity/build/artifacts/generated/common/modules/Audio/AudioBindings.gen.cs:610)
    TankHealth.OnDeath () (at Assets/Scripts/Tank/TankHealth.cs:66)
    TankHealth.TakeDamage (Single amount) (at Assets/Scripts/Tank/TankHealth.cs:46)
    ShellExplosion.OnTriggerEnter (UnityEngine.Collider other) (at Assets/Scripts/Shell/ShellExplosion.cs:39)​

    My shells only explode when they hit a tank, not when they hit the ground or buildings.
    When the tank life is gone it doesn't end the game. I see the tank explosion, though.
    Please help!

    Thanks,
    Rob
     
  12. Pablo_0121

    Pablo_0121

    Joined:
    May 17, 2017
    Posts:
    1
    My tank does not lose health with the contact of the shell, here the script of TankHealth and shellexplosion

    please help!!.

    using UnityEngine;
    using UnityEngine.UI;

    public class TankHealth : MonoBehaviour
    {
    public float m_StartingHealth = 100f;
    public Slider m_Slider;
    public Image m_FillImage;
    public Color m_FullHealthColor = Color.green;
    public Color m_ZeroHealthColor = Color.red;
    public GameObject m_ExplosionPrefab;

    private AudioSource m_ExplosionAudio;
    private ParticleSystem m_ExplosionParticles;
    private float m_CurrentHealth;
    private bool m_Dead;


    private void Awake()
    {
    m_ExplosionParticles = Instantiate(m_ExplosionPrefab).GetComponent<ParticleSystem>();
    m_ExplosionAudio = m_ExplosionParticles.GetComponent<AudioSource>();

    m_ExplosionParticles.gameObject.SetActive(false);
    }


    private void OnEnable()
    {
    m_CurrentHealth = m_StartingHealth;
    m_Dead = false;

    SetHealthUI();
    }

    public void TakeDamage(float amount)
    {
    // Adjust the tank's current health, update the UI based on the new health and check whether or not the tank is dead.
    m_CurrentHealth -= amount;

    SetHealthUI();
    if(m_CurrentHealth <= 0f && !m_Dead)
    {
    OnDeath ();
    }
    }

    private void SetHealthUI()
    {
    // Adjust the value and colour of the slider.
    m_Slider.value = m_CurrentHealth;

    m_FillImage.color = Color.Lerp(m_ZeroHealthColor, m_FullHealthColor, m_CurrentHealth / m_StartingHealth);
    }


    private void OnDeath()
    {
    // Play the effects for the death of the tank and deactivate it.
    m_Dead = true;

    m_ExplosionParticles.transform.position = transform.position;
    m_ExplosionParticles.gameObject.SetActive (true);

    m_ExplosionParticles.Play();

    m_ExplosionAudio.Play();

    gameObject.SetActive (false);
    }
    }


    using UnityEngine;

    public class ShellExplosion : MonoBehaviour
    {
    public LayerMask m_TankMask;
    public ParticleSystem m_ExplosionParticles;
    public AudioSource m_ExplosionAudio;
    public float m_MaxDamage = 100f;
    public float m_ExplosionForce = 1000f;
    public float m_MaxLifeTime = 2f;
    public float m_ExplosionRadius = 5f;


    private void Start()
    {
    Destroy(gameObject, m_MaxLifeTime);
    }


    private void OnTriggerEnter(Collider other)
    {
    // Find all the tanks in an area around the shell and damage them.
    Collider[] colliders = Physics.OverlapSphere(transform.position, m_ExplosionRadius, m_TankMask);

    for (int i = 0; i < colliders.Length; i++)
    {
    Rigidbody targetRigidbody = colliders.GetComponent<Rigidbody>();

    if (!targetRigidbody)
    continue;

    targetRigidbody.AddExplosionForce(m_ExplosionForce, transform.position, m_ExplosionRadius);
    TankHealth targetHealth = targetRigidbody.GetComponent<TankHealth>();

    if (!targetHealth)
    continue;

    float damage = CalculateDamage(targetRigidbody.position);
    targetHealth.TakeDamage(damage);
    }

    m_ExplosionParticles.transform.parent = null;
    m_ExplosionParticles.Play();
    m_ExplosionAudio.Play();
    Destroy(m_ExplosionParticles.gameObject, m_ExplosionParticles.main.duration);
    Destroy(gameObject);
    }

    private float CalculateDamage(Vector3 targetPosition)
    {
    // Calculate the amount of damage a target should take based on it's position.
    Vector3 explosionToTarget = targetPosition - transform.position;
    float explosionDistance = explosionToTarget.magnitude;
    float relativeDistance = (m_ExplosionRadius - explosionDistance) / m_ExplosionRadius;
    float damage = relativeDistance * m_MaxDamage;
    damage = Mathf.Max(0f, damage);
    return 0f;
    }
    }
     
    duddanelly likes this.
  13. RobH99

    RobH99

    Joined:
    May 14, 2017
    Posts:
    5
    Fixed: In the ShellExplosion script, when OnTriggerEnter is called, some code lines that belonged after the 'for' loop were inside it.
     
    Last edited: Jun 11, 2017
  14. RobH99

    RobH99

    Joined:
    May 14, 2017
    Posts:
    5
    ...and...
    Fixed! Like it said, I just had to add an Audio Source to the TankExplosion Prefab. I guess I just didn't make the connection that the Clone was the Prefab.
     
  15. smatsah

    smatsah

    Joined:
    Jun 6, 2017
    Posts:
    2
    Thank you guys first for this EPIC game..

    My game works fine so far. I have a question tho. In phase 6: after charging the tank will fire for sure. What i have noticed that in the tutorial, it fires 2 shells. Mine fires 1 shell only. Now, i do like my version, but I was wondering why does it fire twice in the tutorial??
    This is my code.
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.UI;
    3.  
    4. public class TankShooting : MonoBehaviour
    5. {
    6.     public int m_PlayerNumber = 1;    
    7.     public Rigidbody m_Shell;          
    8.     public Transform m_FireTransform;  
    9.     public Slider m_AimSlider;        
    10.     public AudioSource m_ShootingAudio;
    11.     public AudioClip m_ChargingClip;  
    12.     public AudioClip m_FireClip;      
    13.     public float m_MinLaunchForce = 15f;
    14.     public float m_MaxLaunchForce = 30f;
    15.     public float m_MaxChargeTime = 0.75f;
    16.  
    17.     private string m_FireButton;      
    18.     private float m_CurrentLaunchForce;
    19.     private float m_ChargeSpeed;      
    20.     private bool m_Fired;              
    21.  
    22.  
    23.     private void OnEnable()
    24.     {
    25.         m_CurrentLaunchForce = m_MinLaunchForce;
    26.         m_AimSlider.value = m_MinLaunchForce;
    27.     }
    28.  
    29.  
    30.     private void Start()
    31.     {
    32.         m_FireButton = "Fire" + m_PlayerNumber;
    33.  
    34.         m_ChargeSpeed = (m_MaxLaunchForce - m_MinLaunchForce) / m_MaxChargeTime;
    35.     }
    36.  
    37.  
    38.     private void Update()
    39.     {
    40.         // Track the current state of the fire button and make decisions based on the current launch force.
    41.         m_AimSlider.value = m_MinLaunchForce;
    42.  
    43.         if (m_CurrentLaunchForce >= m_MaxLaunchForce && !m_Fired)
    44.         {// max charge, not yet fired
    45.             m_CurrentLaunchForce = m_MaxLaunchForce;
    46.             Fire ();
    47.         }
    48.         else if (Input.GetButtonDown (m_FireButton))
    49.         {// fire the first time
    50.             m_Fired = false;
    51.             m_CurrentLaunchForce = m_MinLaunchForce;
    52.             m_ShootingAudio.clip = m_ChargingClip;
    53.             m_ShootingAudio.Play ();
    54.         }  
    55.         else if(Input.GetButton(m_FireButton) && !m_Fired)
    56.         {//holding the fire button, not yet fired
    57.             m_CurrentLaunchForce += m_ChargeSpeed * Time.deltaTime;
    58.             m_AimSlider.value = m_CurrentLaunchForce;
    59.         }
    60.         else if(Input.GetButtonUp(m_FireButton) && !m_Fired)
    61.         {//realesed, not yet fired
    62.             Fire();
    63.         }
    64.     }
    65.  
    66.  
    67.     private void Fire()
    68.     {
    69.         // Instantiate and launch the shell.
    70.         m_Fired = true;                                                                                        //Treat as Rigidbody
    71.         Rigidbody shellInstance = Instantiate (m_Shell, m_FireTransform.position, m_FireTransform.rotation) as Rigidbody;
    72.         //Launch the shell
    73.         shellInstance.velocity = m_CurrentLaunchForce * m_FireTransform.forward;
    74.         m_ShootingAudio.clip = m_FireClip;
    75.         m_ShootingAudio.Play ();
    76.         m_CurrentLaunchForce = m_MinLaunchForce;
    77.     }
    78. }
     
  16. twilightZone

    twilightZone

    Joined:
    Oct 10, 2014
    Posts:
    30
    Hello all,
    I have a very stupid question in the Assets folder, we have a file "Readme.asset". When we look this file in the inspector, it contains some text, a picture and two links. Can you explain how you have created this special readme.
    Thanks a lot
     

    Attached Files:

    anasiqbal and megabrobro like this.
  17. megabrobro

    megabrobro

    Joined:
    Jul 8, 2017
    Posts:
    109
    Hi, im just moving over to Unity3d from working in code only with XNA and LibGDX. Unity looks brilliant but very different from how I'm used to working.

    I'm having trouble following the Tanks Tutorial. I have the assets loaded into my project and can follow along, but i don't understand how and when to make the folders myself. I was hoping to learn how to create the game from scratch and importing all the assets as part of the tutorial.

    Is there any other current updated tutorial for unity 5.6 that will cover importing all assets from scratch. I've worked on the RollABall tutorial but this is only using primitives. I'd like to learn next about attaching a texture to the plain. Adding 3d models made in 3rdParty software and adding textures to those models.
     
  18. ukmadorian

    ukmadorian

    Joined:
    Jul 16, 2017
    Posts:
    1
    I have a annoying problem in part 7 to 8.

    When I drag the CameraRig to the CameraControl public object of the GameController it doesn't filled, just continue as "CameraControl(none)" in light gray.

    Can you help me please?
     
  19. caomaru

    caomaru

    Joined:
    Jul 22, 2017
    Posts:
    1
    Hello! I'm making this project for my investigation project at college, and I have a little problem with tutorial nº2. My problem is that I can move the audio and the particles but not the tank, I've revised the tutorial's code like 10 times and idk if it's a code problem or a collision problem or smthng like that. Can anyone help me? Thank you all guys!
     
  20. Dickson2305

    Dickson2305

    Joined:
    Jul 24, 2017
    Posts:
    1
    Hello,
    I've just finished all 8 parts of the tutorial and was wondering how I would go about expanding the game by adding level select and character select, this would be on offline 2 player. I'm fairly new to unity and would like a bit of direction on how to implement this. I want to be able to choose a level, then player 1 & 2 choose there colours?
    Cheers in advance
     
  21. Kainatic

    Kainatic

    Joined:
    May 31, 2017
    Posts:
    5
    Hey, could you pass me copy of the .exe file for Windows PC 32-bit (x86). I really want to try out the mods.

    P.s. I could be your Beta tester if you like. I could debug and collect error reports for you to help straighten your project.
     
  22. bhushan629

    bhushan629

    Joined:
    Aug 29, 2017
    Posts:
    1
    Hello,

    I am using Unity version 2017.1. In Tanks Video Tutorial : 01 Scene Setup, they are doing some ligh baking configuration. but i didn't found those setting in new unity version. so anyone know how to setup lighting setting in unity 2017.1
     
  23. Lord_Scelettron

    Lord_Scelettron

    Joined:
    Sep 2, 2017
    Posts:
    2
    hi,
    i am on unity 2017.1.0f3 and the game manager and the shell explosion scripts does not work could someone give me updated scripts ???
     
  24. Lord_Scelettron

    Lord_Scelettron

    Joined:
    Sep 2, 2017
    Posts:
    2
    when you disable autau lighting the bake button is to the right of it
    I hope that helps you bhushan629
     
  25. jortd

    jortd

    Joined:
    Jul 17, 2017
    Posts:
    3
    I know this is 2 years old by now, but my tank is moving on its own. It's also rotating and I don't know why this happens...
    Can any1 help me?

    Thanks :D
     
  26. jortd

    jortd

    Joined:
    Jul 17, 2017
    Posts:
    3
    Go to Edit>Project Settings>Input

    Set the axis up from 16 to 18

    Name the last two:

    Horizontal3
    Vertical3

    Give a positive button(horizontal means forward, vertical means right)
    Give a negative button(horizontal means backwards, vertical means left)

    Set the gravity to 3
    Dead to 0.001
    Sensitivity to 3

    Snap:eek:n
    Invert:eek:ff

    Type: key or mouse button
    X-Axis
    Get Motion from all joysticks

    Do this for both fields, Horizontal and vertical

    Hope this helps!
    Cheers
     
  27. jortd

    jortd

    Joined:
    Jul 17, 2017
    Posts:
    3
    The scripts still work, maybe try the lesson again?
     
  28. jsteph67

    jsteph67

    Joined:
    Sep 18, 2014
    Posts:
    1
    Question AddExplosionForce, it appears to continues to apply force to my tanks. If I drop the completedTank it works right. But if I am doing it as we go, the tank flies across the screen. When I moved the tank and stop moving it will start moving in the direction of the force. The weird part is, I copy all of the components from the completedTank to the new tank and it is still doing it:
    https://gfycat.com/gifs/detail/RemoteFriendlyFruitbat

    I dropped one of their tanks in and copied all of the same components that same issue. So I am not sure what I am missing.
     
  29. Eliasnd

    Eliasnd

    Joined:
    Nov 14, 2017
    Posts:
    3
    I've downloaded the project and opened it, but there's no Scenes folder and Unity crashes when I try to add the LevelArt prefab.
     
  30. CyberInteractiveLLC

    CyberInteractiveLLC

    Joined:
    May 23, 2017
    Posts:
    306
    Just starting out this project, how hard would it be to make it a split screen and a 3rd person view ?
     
  31. RVRHS_Unity_Student

    RVRHS_Unity_Student

    Joined:
    Dec 1, 2017
    Posts:
    1
    Does anyone know how I could add two tank prefabs using the Game Manager? And how I would change the script to accommodate spawning two different tank prefabs?
     
  32. FTCosta

    FTCosta

    Joined:
    Jan 8, 2018
    Posts:
    5
    Hi. I've scrolled through the thread searching for the answer to this problem:

    I'm having the exact same problem. Can someone help?
    TIA
     
  33. patrickberzins14

    patrickberzins14

    Joined:
    Jan 10, 2018
    Posts:
    1
    i'm currently working on the Tanks tutorial and just finished the coding lesson for moving the tank. When I saved the code and went into Unity to run the game I got the error
    "error CS0006: Metadata file `/Applications/Visual Studio.app/Contents/Resources/lib/monodevelop/AddIns/MonoDevelop.Unity/Editor/SyntaxTree.VisualStudio.Unity.Bridge.dll' could not be found"
    Im fairly new to coding and have no clue what this means. I tried to look online and people had encountered similar issues but nothing worked.

    my script for TankMovement looks like this in the attachment

    Edit: restarted the tutorial and didn't have any other troubles besides my own typo.
     

    Attached Files:

    Last edited: Jan 12, 2018
  34. The_Rogue12

    The_Rogue12

    Joined:
    Jan 28, 2018
    Posts:
    19
    HELP!! The control for my 2nd tank (the red one) doesn't work! The arrow keys don't do anything, but the enter key will run the shooting script perfectly. Here is my script for the tank movement (it is on windows):

    using UnityEngine;

    public class TankMovement : MonoBehaviour
    {
    public int m_PlayerNumber = 1;
    public float m_Speed = 12f;
    public float m_TurnSpeed = 180f;
    public AudioSource m_MovementAudio;
    public AudioClip m_EngineIdling;
    public AudioClip m_EngineDriving;
    public float m_PitchRange = 0.2f;


    private string m_MovementAxisName;
    private string m_TurnAxisName;
    private Rigidbody m_Rigidbody;
    private float m_MovementInputValue;
    private float m_TurnInputValue;
    private float m_OriginalPitch;


    private void Awake()
    {
    m_Rigidbody = GetComponent<Rigidbody>();
    }


    private void OnEnable ()
    {
    m_Rigidbody.isKinematic = false;
    m_MovementInputValue = 0f;
    m_TurnInputValue = 0f;
    }


    private void OnDisable ()
    {
    m_Rigidbody.isKinematic = true;
    }


    private void Start()
    {
    m_MovementAxisName = "Vertical" + m_PlayerNumber;
    m_TurnAxisName = "Horizontal" + m_PlayerNumber;

    m_OriginalPitch = m_MovementAudio.pitch;
    }


    private void Update()
    {
    // Store the player's input and make sure the audio for the engine is playing.
    m_MovementInputValue = Input.GetAxis (m_MovementAxisName);
    m_TurnInputValue = Input.GetAxis (m_TurnAxisName);

    EngineAudio ();
    }


    private void EngineAudio()
    {
    // Play the correct audio clip based on whether or not the tank is moving and what audio is currently playing.

    if (Mathf.Abs (m_MovementInputValue) < 0.1f && Mathf.Abs (m_TurnInputValue) < 0.1f)
    {
    if (m_MovementAudio.clip == m_EngineDriving)
    {
    m_MovementAudio.clip = m_EngineIdling;
    m_MovementAudio.pitch = Random.Range (m_OriginalPitch - m_PitchRange, m_OriginalPitch + m_PitchRange);
    m_MovementAudio.Play ();
    }
    }
    else
    {
    if (m_MovementAudio.clip == m_EngineIdling)
    {
    m_MovementAudio.clip = m_EngineDriving;
    m_MovementAudio.pitch = Random.Range (m_OriginalPitch - m_PitchRange, m_OriginalPitch + m_PitchRange);
    m_MovementAudio.Play ();
    }
    }
    }


    private void FixedUpdate()
    {
    // Move and turn the tank.
    Move ();
    Turn ();
    }


    private void Move()
    {
    // Adjust the position of the tank based on the player's input.
    Vector3 movement = transform.forward * m_MovementInputValue * m_Speed * Time.deltaTime;

    m_Rigidbody.MovePosition (m_Rigidbody.position + movement);

    }


    private void Turn()
    {
    // Adjust the rotation of the tank based on the player's input.
    float turn = m_TurnInputValue * m_TurnSpeed * Time.deltaTime;

    Quaternion turnRotation = Quaternion.Euler (0f, turn, 0f);

    m_Rigidbody.MoveRotation (m_Rigidbody.rotation * turnRotation);
    }
    }

    Edit: I compared my script to the one the people doing the seminar for the tank were using, and there were no changes, so I am wondering if it is something with the Unity edior. Can somebody give me help? Thanks.
     
    Last edited: Jan 28, 2018
  35. abhipot84

    abhipot84

    Joined:
    Jan 28, 2018
    Posts:
    2
    Hello Sir I have a question about how to change the tanks colors so one is green and the other is blue please reply.
     
  36. abhipot84

    abhipot84

    Joined:
    Jan 28, 2018
    Posts:
    2
    How do you change the tanks color pleas tell
     
  37. The_Rogue12

    The_Rogue12

    Joined:
    Jan 28, 2018
    Posts:
    19
    No, I won't tell because you didn't ask NICELY!
     
  38. The_Rogue12

    The_Rogue12

    Joined:
    Jan 28, 2018
    Posts:
    19
    To change the tank color, you have to set the spawn point gizmo to be one red and one blue.
     
  39. The_Rogue12

    The_Rogue12

    Joined:
    Jan 28, 2018
    Posts:
    19
    HELP!! The control for my 2nd tank (the red one) doesn't work! The arrow keys don't do anything, but the enter key will run the shooting script perfectly. Here is my script for the tank movement (it is on windows):

    using UnityEngine;

    public class TankMovement : MonoBehaviour
    {
    public int m_PlayerNumber = 1;
    public float m_Speed = 12f;
    public float m_TurnSpeed = 180f;
    public AudioSource m_MovementAudio;
    public AudioClip m_EngineIdling;
    public AudioClip m_EngineDriving;
    public float m_PitchRange = 0.2f;


    private string m_MovementAxisName;
    private string m_TurnAxisName;
    private Rigidbody m_Rigidbody;
    private float m_MovementInputValue;
    private float m_TurnInputValue;
    private float m_OriginalPitch;


    private void Awake()
    {
    m_Rigidbody = GetComponent<Rigidbody>();
    }


    private void OnEnable ()
    {
    m_Rigidbody.isKinematic = false;
    m_MovementInputValue = 0f;
    m_TurnInputValue = 0f;
    }


    private void OnDisable ()
    {
    m_Rigidbody.isKinematic = true;
    }


    private void Start()
    {
    m_MovementAxisName = "Vertical" + m_PlayerNumber;
    m_TurnAxisName = "Horizontal" + m_PlayerNumber;

    m_OriginalPitch = m_MovementAudio.pitch;
    }


    private void Update()
    {
    // Store the player's input and make sure the audio for the engine is playing.
    m_MovementInputValue = Input.GetAxis (m_MovementAxisName);
    m_TurnInputValue = Input.GetAxis (m_TurnAxisName);

    EngineAudio ();
    }


    private void EngineAudio()
    {
    // Play the correct audio clip based on whether or not the tank is moving and what audio is currently playing.

    if (Mathf.Abs (m_MovementInputValue) < 0.1f && Mathf.Abs (m_TurnInputValue) < 0.1f)
    {
    if (m_MovementAudio.clip == m_EngineDriving)
    {
    m_MovementAudio.clip = m_EngineIdling;
    m_MovementAudio.pitch = Random.Range (m_OriginalPitch - m_PitchRange, m_OriginalPitch + m_PitchRange);
    m_MovementAudio.Play ();
    }
    }
    else
    {
    if (m_MovementAudio.clip == m_EngineIdling)
    {
    m_MovementAudio.clip = m_EngineDriving;
    m_MovementAudio.pitch = Random.Range (m_OriginalPitch - m_PitchRange, m_OriginalPitch + m_PitchRange);
    m_MovementAudio.Play ();
    }
    }
    }


    private void FixedUpdate()
    {
    // Move and turn the tank.
    Move ();
    Turn ();
    }


    private void Move()
    {
    // Adjust the position of the tank based on the player's input.
    Vector3 movement = transform.forward * m_MovementInputValue * m_Speed * Time.deltaTime;

    m_Rigidbody.MovePosition (m_Rigidbody.position + movement);

    }


    private void Turn()
    {
    // Adjust the rotation of the tank based on the player's input.
    float turn = m_TurnInputValue * m_TurnSpeed * Time.deltaTime;

    Quaternion turnRotation = Quaternion.Euler (0f, turn, 0f);

    m_Rigidbody.MoveRotation (m_Rigidbody.rotation * turnRotation);
    }
    }

    Edit: I compared my script to the one the people doing the seminar for the tank were using, and there were no changes, so I am wondering if it is something with the Unity editor. Can somebody give me help? Thanks.
     
  40. Tim_Wilson

    Tim_Wilson

    Joined:
    Jan 30, 2018
    Posts:
    2
    I am new to Unity and this is the second tutorial I have done. I had just got through phase 6 (firing shells) when I realized that when I would fire the shells they would explode as soon as I let go of the space bar. My following code is the code used for firing the shells

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.UI;
    3.  
    4. public class TankShooting : MonoBehaviour
    5. {
    6.     public int m_PlayerNumber = 1;      
    7.     public Rigidbody m_Shell;          
    8.     public Transform m_FireTransform;  
    9.     public Slider m_AimSlider;          
    10.     public AudioSource m_ShootingAudio;
    11.     public AudioClip m_ChargingClip;    
    12.     public AudioClip m_FireClip;        
    13.     public float m_MinLaunchForce = 15f;
    14.     public float m_MaxLaunchForce = 30f;
    15.     public float m_MaxChargeTime = 0.75f;
    16.  
    17.    
    18.     private string m_FireButton;        
    19.     private float m_CurrentLaunchForce;
    20.     private float m_ChargeSpeed;        
    21.     private bool m_Fired;              
    22.  
    23.  
    24.     private void OnEnable()
    25.     {
    26.         m_CurrentLaunchForce = m_MinLaunchForce;
    27.         m_AimSlider.value = m_MinLaunchForce;
    28.     }
    29.  
    30.  
    31.     private void Start()
    32.     {
    33.         m_FireButton = "Fire" + m_PlayerNumber;
    34.  
    35.         m_ChargeSpeed = (m_MaxLaunchForce - m_MinLaunchForce) / m_MaxChargeTime;
    36.     }
    37.    
    38.  
    39.     private void Update()
    40.     {
    41.         m_AimSlider.value = m_MinLaunchForce;
    42.  
    43.         if(m_CurrentLaunchForce >= m_MaxLaunchForce && !m_Fired)
    44.         {
    45.             m_CurrentLaunchForce = m_MaxLaunchForce;
    46.             Fire ();
    47.         }
    48.         else if(Input.GetButtonDown(m_FireButton))
    49.         {
    50.             m_Fired = false;
    51.             m_CurrentLaunchForce = m_MinLaunchForce;
    52.  
    53.             m_ShootingAudio.clip = m_ChargingClip;
    54.             m_ShootingAudio.Play();
    55.         }
    56.         else if(Input.GetButton(m_FireButton) && !m_Fired)
    57.         {
    58.             m_CurrentLaunchForce += m_ChargeSpeed * Time.deltaTime;
    59.  
    60.             m_AimSlider.value = m_CurrentLaunchForce;
    61.         }
    62.         else if(Input.GetButtonUp(m_FireButton) && !m_Fired)
    63.         {
    64.             Fire ();
    65.         }
    66.     }
    67.  
    68.  
    69.     private void Fire()
    70.     {
    71.         m_Fired = true;
    72.  
    73.         Rigidbody shellInstance = Instantiate (m_Shell, m_FireTransform.position, m_FireTransform.rotation) as Rigidbody;
    74.  
    75.         shellInstance.velocity = m_CurrentLaunchForce * m_FireTransform.forward;
    76.  
    77.         m_ShootingAudio.clip = m_FireClip;
    78.         m_ShootingAudio.Play ();
    79.  
    80.         m_CurrentLaunchForce = m_MinLaunchForce;
    81.     }
    82. }
    83.  
    and after you fire the tank will move backwards due to the explosion force. And as far as I can tell it blows the tank a lot further than the video shows. The m_ExplosionForce is set to 1000f. Also after the blow it seems to want to rotate along the Y-Axis.

    I would appreciate any help in troubleshooting this.
     
  41. nwzebra

    nwzebra

    Joined:
    Dec 4, 2015
    Posts:
    16
    Just shooting from the hip, but check to make sure your fireTransform isn't inside your tank collider. Your shell would be instantiated in your tank collider and instantly explode.
     
  42. nwzebra

    nwzebra

    Joined:
    Dec 4, 2015
    Posts:
    16
    Look for Horizontal2 and Vertical2 in Edit/Project Setting/Input. If your keyboard doesn't have separate arrow keys, check your Num Lock.
     
  43. nwzebra

    nwzebra

    Joined:
    Dec 4, 2015
    Posts:
    16
    The GameManager has an array of TankManagers which hold the color for each tank.
     
  44. The_Rogue12

    The_Rogue12

    Joined:
    Jan 28, 2018
    Posts:
    19
    Thanks, but I’ve already tried that. I even tried to change the controls from the arrow keys to something else on my keyboard. I noticed that whenever I use the control keys for the tank, particles will come out but the tank won’t move.
     
  45. The_Rogue12

    The_Rogue12

    Joined:
    Jan 28, 2018
    Posts:
    19

    Go to the tutorial page in unity, and copy the code there.
     
  46. The_Rogue12

    The_Rogue12

    Joined:
    Jan 28, 2018
    Posts:
    19
    I need help with my tank game. When I press the arrow keys, particles come out from the red tank but it doesn’t move! It can shoot but it can’t move.
     
  47. Tim_Wilson

    Tim_Wilson

    Joined:
    Jan 30, 2018
    Posts:
    2
    @nwzebra

    Thank you for the suggestion.

    I tried moving the FireTransform far away from the tank and it didn't blow up the tank. Instead it blew up in the FireTransform. Instead of shooting, it blew up as soon as it was instantiated.

    I appreciate any more ideas you have.
     
  48. The_Rogue12

    The_Rogue12

    Joined:
    Jan 28, 2018
    Posts:
    19
    I need help with my tank game. When I press the arrow keys, particles come out from the red tank but it doesn’t move! It can shoot but it can’t move.
     
  49. The_Rogue12

    The_Rogue12

    Joined:
    Jan 28, 2018
    Posts:
    19
    I need help with my tank game. When I press the arrow keys, particles come out from the red tank but it doesn’t move! It can shoot but it can’t move.
     
  50. The_Rogue12

    The_Rogue12

    Joined:
    Jan 28, 2018
    Posts:
    19
    I need help with my tank game. When I press the arrow keys, particles come out from the red tank but it doesn’t move! It can shoot but it can’t move.