Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Space Shooter Tutorial Q&A

Discussion in 'Community Learning & Teaching' started by Adam-Buckner, Mar 26, 2015.

  1. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    You should be able to attach images or link the to a host URL, like drop box, tiny pic or gyazo.

    Fwiw: I've never heard not seen of this... It's probably not a bug but a unique way of doing things. They restarting everything and trying again, then if this doesn't fix it, post screen shots, movies and a more complete description of all steps involved.
     
  2. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    If you want to get a reference to the GameObject holding the UI Text element in the hierarchy (usually called text by default) you will need to use GameObject.Find. If you want to get a reference to the Text component on a game object, once you have the GameObject reference, you need to use GetComponent<Text> on the GameObject.

    Also, don't forget you need your UI namespace to get any UI element.
     
    Aenigmaticus likes this.
  3. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
  4. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Please report any reproducible bugs you can find they can be fixed.
     
  5. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Definitely report what you find with beta software so things can be fixed. Include a good reproducible project.
     
  6. IronDaddy

    IronDaddy

    Joined:
    Jan 26, 2016
    Posts:
    4
    Thank you buddy!! : ) Yeah!~~
     
  7. spromise2007

    spromise2007

    Joined:
    Dec 6, 2015
    Posts:
    21
    Hello Adam,

    I haven't been on for a while. I realize that this is probably the wrong thread, but i'm having a problem with one of the tutorials that you recommended, actually it's a "Live Lesson". ij couldn't find a forum thread for this tutorial or i would've posted this message there. There wasn't any FAQ file either. The asset link is totally different from the asset used in the video and i start off totally lost. i imported the one from the link, as the one in the video doesn't seem to exist any more. However, there is no convenient preexisting HUD or anything under the Main Camera scene and i don't see any other scenes.

    Thank you,
    Sean
     
  8. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Post in the live training thread.
     
  9. Aenigmaticus

    Aenigmaticus

    Joined:
    Apr 7, 2016
    Posts:
    54
    http://forum.unity3d.com/threads/free-live-online-training-from-unity-technologies.204688/
    Don't forget the link!
     
  10. dtkeijser

    dtkeijser

    Joined:
    Apr 26, 2016
    Posts:
    1
    Hi got a 2 questions for some reason mine bolts will not go away when it collides with the boundary i solved it by using the destroybytime code but i dont know how I can make it work with the boundary the code. Mine other question is when i try to use try to get the enemy ship to shoot bolts it explodes it self I used the codes provided in the tutorial
     

    Attached Files:

  11. FireHawkX

    FireHawkX

    Joined:
    Apr 26, 2016
    Posts:
    28
    I am making a small game using all the tutorials i have built... however I am getting the weirdest bug with this particular scene... I actually already made a unity answer post about it :
    http://answers.unity3d.com/questions/1177133/c-pause-menu-buttons-not-working-in-only-1-scene.html

    Somehow my pause menu doesnt work in THIS scene... the menu opens and close fine, but no button works at all... and it works in all others games (scenes)... i dont understand what could be causing buttons to stop working with this particular game but not with rollerball or nightmare-shooter...


    EDIT : just wanted to say i found the solution... simply adding a "UI EventSystem" in the scene fixed it... no idea why that is being added by itself with some other elements... but that fixed the menu buttons not responding :)
     
    Last edited: Apr 27, 2016
  12. GodzWrath

    GodzWrath

    Joined:
    Apr 27, 2016
    Posts:
    10
    Currently having a rather peculiar issue. When I press down the ctrl key for firing when running the game I lose the ability to move the ship, however if I am moving the ship, then press it down I can still move the ship, but only in the direction that it's already moving. Any help would be greatly appreciated, thanks!

    Seems like this isn't my only issue. I also can't seem to get the asteroid to realize it's being shot. The game doesn't detect the asteroid shot even though my code is identical to the code that is provided.
    Nevermind, Figured it out. I just had to untab/correctly format some of the code.
     

    Attached Files:

    Last edited: Apr 27, 2016
  13. Shags

    Shags

    Joined:
    Apr 28, 2016
    Posts:
    24
    Hi Adam,
    I loved doing this tutorial so much I have created my own artwork for it, and replaced all the original art for the game. Can I put my take of the game on the app store? also can you help me I'm trying to add a shop where you can purchase rate of fire modifiers. I have been watching the "Creating An In-Game Shop" live training episode. I have created some script able objects but I don't know how to get them to modify the rate of fire in the game controller (if that is the right place for the changes to be made). This tutorial has been so much fun!
     
  14. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    These problems all sound like issues with tags and layers. Have you checked your code to make sure the tags are all correct? Spelling and capitalisation count.
     
  15. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    You need an EventSystem to process click and touch events. This is added automatically if you create any hi element from the create menu. If you add the components yourself to empty GameObjects, you need to manually add the EventSystem.
     
  16. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Glad you figured it out. If you have any other problems, don't hesitate to post.
     
  17. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Yes, you can publish to the App Store. All of our material is free for you to use commercially, as long as you're not reselling assets.

    You'll have to ask @Matthew Schell about the in game shop. He did that episode. To modify the rate of fire, you either need to make it public and affect it, or better yet, create a public function that you can call that sets the rate of fire.
     
  18. GodzWrath

    GodzWrath

    Joined:
    Apr 27, 2016
    Posts:
    10
    Hiya, another quick question here. I have been trying to make the space shooter game quite a bit more advanced and have succeeded on some fronts, but have limited coding knowledge. I have not been able to avoid the issue of the bolts destroying each other when I try to use multiple shots at once, just as you had that issue in the live advanced space shooter. I have tried multiple things, but simply think I may lack the coding knowledge or experience to fully create a true solution, as the only thing I've been able to do is make the bolts pass through everything but themselves for some odd reason.

    Also I was wondering if you amy have any tips on making this game first person? I was thinking it could be a cool perspective since it's all done in 3D anyways, the controls could be the same and the camera could be bound to the player ship, possibly third person since it would likely be easier though.

    Thanks for any tips or suggestions and thanks for making these fun tutorials!
     
  19. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    For the bolts, I would look into tags and layers and physics collision layers to solve your problem.

    For a first person game, you can use the models and assets, but the game is fundamentally different in its control scheme and how you move the ship. You would need to experiment with the input axes as vertical will be thrust on a local scale and horizontal would be some form of 2 axis turn.
     
  20. GodzWrath

    GodzWrath

    Joined:
    Apr 27, 2016
    Posts:
    10
    How do I compare two different tags on a collision? Such as determining if an object tagged PowerUp hits an onject tagged Player the script will do something specific. I haven't quite been able to figure this one out.
     
  21. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Well if the script is on a GameObject that's tagged as PowerUp, it only needs to check if it hits the player, as the PowerUp tag is implicit. If you really want to check you just say if (gameObject.tag == "PowerUp" && other.gameObject.tag == "Player") {}
     
  22. squall-lionheart

    squall-lionheart

    Joined:
    Dec 22, 2012
    Posts:
    7
    I've tried looking through this and it mostly goes over my head at the moment.

    I've managed to narrow it down to the "newPosition" variable that is causing the issue, it is jumping to a new value rather than just slowly incrementing/decreasing :/

    This offer still valid and also possible? should I just export asset package and upload?
     
  23. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    In FixedUpdate, is this line directly from the extension tutorial? Or did you modify this?
    Code (csharp):
    1.  float newManeuver = Mathf.MoveTowards(rb.velocity.x, targetManeuver, Time.deltaTime * smoothing);
     
  24. Aenigmaticus

    Aenigmaticus

    Joined:
    Apr 7, 2016
    Posts:
    54
    Insofar as I understand, Squall is extending it beyond the tutorials at this point. I will help Squall in a personal conversation, but no longer here as it does not fit the tutorial anymore.
     
  25. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Yeah, just trying to get my head around the issue. I'm not sure using move towards to make the value of velocity meet the value of a position is the correct thing to do, but I don't remember this part off the top of my head.
     
  26. Aenigmaticus

    Aenigmaticus

    Joined:
    Apr 7, 2016
    Posts:
    54
    Tutorial-wise, the hazard speed variable is not changed throughout the gameplay, but rather defined in the GameObject -> "GameController" -> Inspector.
    Squall_Lionheart wants a 'wave speed increment' logic, which can be achieved in the GameController script.

    Squall_Lionheart also wants to adjust the speed of the background scroller with respect to the hazard speed.

    I believe the problems can both be solved in the GameController script. I have personally solved the first part; but the second... I need to isolate a strange problem. I'll get back to you guys when I figure it out.
     
  27. somuchdirt74

    somuchdirt74

    Joined:
    Apr 28, 2016
    Posts:
    3
    I'm stuck. my code no longer destroys the asteroid when I shoot at it. However, it shows the explosion when I shoot it. The asteroid gets destroyed when colliding with my ship. I'm sure I messed up somewhere but I can't figure it out.

    DestroyByContact:

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class DestroyByContact : MonoBehaviour
    5. {
    6.  
    7.     public GameObject explosion;
    8.     public GameObject playerExplosion;
    9.     void OnTriggerEnter(Collider other)
    10.  
    11.     {
    12.         if (other.tag == "Boundary")
    13.         {
    14.             return;
    15.         }
    16.         Instantiate (explosion, transform.position, transform.rotation);
    17.         if (other.tag == "Player")
    18.         {  
    19.             //Debug.Log (other.name);
    20.             Instantiate (playerExplosion, other.transform.position, other.transform.rotation);
    21.             Destroy (other.gameObject);
    22.             Destroy (gameObject);
    23.      
    24.         }
    25.  
    26.     }
    27. }

    PlayerController:

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. [System.Serializable]
    5. public class Boundary
    6. {
    7.     public float xMin, xMax, zMin, zMax;
    8. }
    9. public class PlayerController : MonoBehaviour
    10. {    
    11.     private Rigidbody rb;
    12.  
    13.     public float speed;
    14.     public float tilt;
    15.     public Boundary boundary;
    16.  
    17.     public GameObject shot;
    18.     public Transform shotSpawn;
    19.     public float fireRate;
    20.  
    21.     private float nextFire;
    22.  
    23.     void Update()
    24.     {
    25.         if (Input.GetButton("Fire1") && Time.time > nextFire)
    26.         {
    27.             nextFire = Time.time + fireRate;
    28.             //GameObject clone =
    29.             Instantiate(shot, shotSpawn.position, shotSpawn.rotation); //as GameObject;
    30.         }
    31.     }
    32.     void FixedUpdate()
    33.     {
    34.         rb = GetComponent<Rigidbody>();
    35.         float moveHorizontal = Input.GetAxis ("Horizontal");
    36.         float moveVertical = Input.GetAxis ("Vertical");
    37.  
    38.         Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
    39.         rb.velocity = movement * speed;
    40.  
    41.         rb.position = new Vector3
    42.         (  
    43.             Mathf.Clamp (rb.position.x, boundary.xMin, boundary.xMax),
    44.             0.0f,
    45.             Mathf.Clamp (rb.position.z, boundary.zMin, boundary.zMax)
    46.         );
    47.  
    48.         rb.rotation = Quaternion.Euler (0.0f,0.0f,rb.velocity.x * -tilt);
    49.     }
    50.  
    51.  
    52. }



     
  28. GodzWrath

    GodzWrath

    Joined:
    Apr 27, 2016
    Posts:
    10
    Currently trying to figure out how to pause the game and make a pause screen. I have not been successful in pausing the game by setting Time.timeScale = 0. For some reason this does not seem to affect the game. Does anyone have any ideas on how to fix this/make the game pause, when for example the P key is pressed?


    I have tried

    if (Input.GetKeyDown(KeyCode.F) && gamePaused == false)
    {
    Time.timeScale = 0F;
    gamePaused = true;
    }
    if (Input.GetKeyDown(KeyCode.F) && gamePaused == true)
    {
    Time.timeScale = 1F;
    gamePaused = false;
    }

    and it did not work. (this was done in Update and gamePaused was defined earlier as a bool and initially set = false in Start).
     
  29. GodzWrath

    GodzWrath

    Joined:
    Apr 27, 2016
    Posts:
    10

    One thing I noticed with your Asteroid was that the capsule collider is not set to be a trigger, try setting the asteroid collider to a trigger and your problem should go away I think.
     
  30. somuchdirt74

    somuchdirt74

    Joined:
    Apr 28, 2016
    Posts:
    3
    Doesn't work. I get the same results. Also, my shots pierces through the asteroid. So the laser beams don't get destroyed til they leave the boundary.
     
  31. GodzWrath

    GodzWrath

    Joined:
    Apr 27, 2016
    Posts:
    10
    Maybe this;

    1. if (other.tag == "Boundary" || other.tag == "Enemy")
    2. {
    3. return;
    4. }
    This is how my code looks sorta, though mine has other.CompareTag instead of just other.tag
     
  32. somuchdirt74

    somuchdirt74

    Joined:
    Apr 28, 2016
    Posts:
    3
    Don't think that this will work for me. I'm at the "spawning waves" part of the tutorial so I don't have an enemy to tag yet. It used to work. I didn't notice this problem until the end of "game controller" tutorial.
     
  33. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    I think he's also trying at adjust the enemy ship target to target the player. I don't have time right now to compare his script with the tutorial. I know the tutorial worked well enough. I guess he'll have to keep working through history modifications until he gets it correct.
     
  34. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Take a look at our live training archives where we do exactly that - make a pause screen.
     
  35. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Have you gone back and compared your code with the completed code on the tutorial page?
     
  36. KAYUMIY

    KAYUMIY

    Joined:
    Nov 12, 2015
    Posts:
    115
    I have a simple question. When I am converting my project, there is not any "I phone Wide" in Aspect size.
    Should I have create myself?
     

    Attached Files:

    Last edited: May 2, 2016
  37. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    This may depend upon what your build target is, but if you'd like to make your own profile for any build target, you might as well go ahead.
     
  38. Aenigmaticus

    Aenigmaticus

    Joined:
    Apr 7, 2016
    Posts:
    54
    For widescreen, you just need to reverse the values in the Unity PlayerSettings from 900x600 to 600x900 (File Menu -> Build Settings -> Player Settings -> look at Inspector.)

    Note that not all iPhones share the same resolution. So:

    iPhone resolution chart:
    http://www.paintcodeapp.com/news/ultimate-guide-to-iphone-resolutions

    I'm afraid I have no intention for mobile dev, so I have no advice to give beyond this. However, I do believe you need to find a switch that defines whether the application is in Portrait mode vs Widescreen mode. Don't trust me on this though, you must do you own research for it!

    Edit: I will advice you to use the smallest resolution with respect to the iPhone series of devices, and find a way to scale up with respect to the devices actual resolution later.
     
    Last edited: May 2, 2016
  39. squall-lionheart

    squall-lionheart

    Joined:
    Dec 22, 2012
    Posts:
    7
    the line in Fixed Update in the Enemy script is not altered, the only change I did was make targetManeuver the same x Position as the players in the Evade function (as shown in the "Extending Space Shooter" video right at the end when a viewer asks how to get the ship to chase the player).

    I have the wave system implemented and once a new round starts I increase the scrollSpeed variable in the BGScroller Script, however, once the change is made, the z Position of the Background jumps by 3 or 4 (goes from 26 to 22, etc..) and the newPosition variable also jumps by 3 or 4 (goes from 25 to 22, etc..)
     
  40. Aenigmaticus

    Aenigmaticus

    Joined:
    Apr 7, 2016
    Posts:
    54
    I stand corrected: I've so far had to modify the GameController script, DestroyByContact script, and BGScroller script. I'm current trying to find a nullref issue, and once done, I'll show you the steps.

    I'll see what I can do with that problem, and get back to you later.

    The problem in a nutshell: the current use of Mathf.Repeat is improper: Look at "Time.time * speed"... and think about it when 'speed' is changed. It will result with a 'jumping' problem.

    Example:
    --- 10 seconds * 1 speed = offset of 10 units;
    lets say we change 'speed' to 2:
    --- 10 seconds * 2 speed = offset of 20 units.
     
    Last edited: May 3, 2016
  41. cristi96

    cristi96

    Joined:
    May 3, 2016
    Posts:
    2
    Hello,
    I have finished this tutorial recently and I wanted to customize my project, however I got some issues while I was trying to keep and update the score through different scenes/levels.
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using UnityEngine.SceneManagement;
    4.  
    5. public class GameController : MonoBehaviour
    6. {
    7.     public GameObject[] hazards;
    8.     public Vector3 spawnValues;
    9.     public int hazardCount;
    10.     public float spawnWait;
    11.     public float startWait;
    12.     public float waveWait;
    13.     public float levelWait;
    14.     public int waveCount;
    15.  
    16.  
    17.     public GUIText scoreText;
    18.     public GUIText restartText;
    19.     public GUIText gameOverText;
    20.     public GUIText levelText;
    21.  
    22.     private int displayLevel = 1;
    23.     private int level = 1;
    24.     private bool gameOver;
    25.     private bool restart;
    26.     private bool levels;
    27.     // private bool created = false;
    28.     private int score;
    29.  
    30.  
    31.    /* void Awake() // I tried this method, but it doesn't work properly.
    32.     {
    33.         if (!created)
    34.         {
    35.             DontDestroyOnLoad(scoreText.gameObject);
    36.             created = true;
    37.         }
    38.         else
    39.         {
    40.             Destroy(scoreText.gameObject);
    41.         }
    42.     } */
    43.  
    44.  
    45.     void Start()
    46.     {
    47.         gameOver = false;
    48.         restart = false;
    49.         levelText.text = "";
    50.         restartText.text = "";
    51.         gameOverText.text = "";
    52.         score = 0;
    53.         UpdateScore();
    54.         StartCoroutine(SpawnWaves());
    55.  
    56.     }
    57.  
    58.  
    59.  
    60.  
    61.     void Update()
    62.     {
    63.  
    64.  
    65.         if (restart)
    66.         {
    67.             if (Input.GetKeyDown(KeyCode.R))
    68.             {
    69.                 SceneManager.LoadScene(0);
    70.             }
    71.         }
    72.     }
    73.  
    74.     IEnumerator SpawnWaves()
    75.     {
    76.         yield return new WaitForSeconds(startWait);
    77.         while (true)
    78.         {
    79.             for (int i = 0; i < hazardCount; i++)
    80.             {
    81.                 GameObject hazard = hazards[Random.Range(0, hazards.Length)];
    82.                 Vector3 spawnPosition = new Vector3(Random.Range(-spawnValues.x, spawnValues.x), spawnValues.y, spawnValues.z);
    83.                 Quaternion spawnRotation = Quaternion.identity;
    84.                 Instantiate(hazard, spawnPosition, spawnRotation);
    85.                 yield return new WaitForSeconds(spawnWait);
    86.             }
    87.             yield return new WaitForSeconds(waveWait);
    88.  
    89.             for (int i = 0; i < waveCount; i++) // I use this to create a number of waves for each level.
    90.             {
    91.                 waveCount--;
    92.             }
    93.  
    94.             if (gameOver)
    95.             {
    96.                 restartText.text = "Press 'R' for Restart";
    97.                 restart = true;
    98.                 break;
    99.             }
    100.             else
    101.                 if (waveCount == 0) // Here, I break the while loop and go on with the nwxt level.
    102.             {
    103.                 displayLevel++;
    104.                 levelText.text = "Level " + displayLevel;
    105.                 levels = true;
    106.                 break;
    107.             }
    108.         }
    109.                 if (levels)
    110.             {
    111.             SceneManager.LoadScene(level);
    112.                 level++;
    113.             yield return new WaitForSeconds(levelWait);
    114.  
    115.         }
    116.        
    117.     }
    118.  
    119.  
    120.  
    121.  
    122.  
    123.     public void AddScore(int newScoreValue)
    124.     {
    125.         score += newScoreValue;
    126.         UpdateScore();
    127.     }
    128.  
    129.   void UpdateScore()
    130.     {
    131.         scoreText.text = "Score: " + score;
    132.     }
    133.  
    134.     public void GameOver()
    135.     {
    136.         gameOverText.text = "Game Over!";
    137.         gameOver = true;
    138.     }
    139.  
    140. }
    I also tried using other methods or adding new scripts. Do you guys have any ideas?
     
  42. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    You may want to look into "DontDestroyOnLoad" and keep things like your GameController persistently through all of the levels. You can also look into loading levels additively and removing them when they are done to a "persistent" scene that holds only your GameController.
     
  43. cristi96

    cristi96

    Joined:
    May 3, 2016
    Posts:
    2
    Do you mean to write something like this: " DontDestroyOnLoad(GameController.gameObject);"?
    I tried to keep the scoreText, but this function just overwrite it in the next level.
     
  44. Aenigmaticus

    Aenigmaticus

    Joined:
    Apr 7, 2016
    Posts:
    54
    PlayerPrefs can help you with storing persistant data: http://docs.unity3d.com/ScriptReference/PlayerPrefs.html
     
  45. Drock1035

    Drock1035

    Joined:
    Feb 10, 2016
    Posts:
    1
    Hi Adam, I'm running through this tutorial and I've run into an issue with the boundary that is supposed to delete our shots. My shots are working normally before i attatch the "DestroyByBoundary" script, albeit they arent getting deleted from the hierachy. However, once i add the script, my shots are almost instantly deleted from the game as soon as they appear. they don't travel to the end of the game view, they're just gone. I'm really scratching my head on this one, does anyone else have a similar problem?
     
  46. Jovy83

    Jovy83

    Joined:
    Feb 28, 2015
    Posts:
    15
    Got a question. In the Roll a ball tutorial, we rotated the pickups in the Update function by giving it an turn amount (in Vector3 ofcourse) and multiplying it by Time.deltaTime.

    Also for the camera tracking the player ball, we moved the camera in the LateUpdate but we did not multiply it by Time.deltaTime

    In this Space Shooter tutorial, we moved and rotated the ship by setting the velocity and rotation of its rigidbody but we did not multiply it by Time.deltaTime.

    When should we multiply by Time.deltaTime? I understand it's for frame independency when moving something. I'm assuming we only need it in the Update function? Since we deal with rigidbodies in the FixedUpdate and camera tracking in the LateUpdate. Please correct me if I'm wrong.

    Thanks
     
  47. Aenigmaticus

    Aenigmaticus

    Joined:
    Apr 7, 2016
    Posts:
    54
    In physics, [a crude from of] acceleration is "delta.time * distance", where 'delta.time' is a time segment... In Unity, the value in 'Time.deltaTime' is the time taken to compute the last frame. As you saw in Roll a Ball, the ball is accelerated when moved. The camera's coordinates is offsetted relative to the ball's coordinate, and the Y axis is locked.

    In Space Shooter, the camera's coordinates is fixed, and instead gives you the perception of motion with your player character. There is no acceleration: move up, and your character goes up a fixed speed, not based off acceleration.

    You can directly use the information you gained from the Roll a Ball tutorial and apply it to the Space Shooter tutorial. In fact, you've piqued my curiousity of how it would be in game... I must test this some time!

    Also, if you wish to use proper acceleration with a lot of objects, I will advise you to research 'Time.fixedDeltaTime' (a physics tick, not a frame tick like 'Time.deltaTime'). http://docs.unity3d.com/ScriptReference/Time-fixedDeltaTime.html
     
    Last edited: May 4, 2016
  48. Aenigmaticus

    Aenigmaticus

    Joined:
    Apr 7, 2016
    Posts:
    54
    Can you please share your code here? Without it, it seems you have it fired on the OnTriggerEnter event, rather then the proper OnTriggerExit event. The reason is because you want the bolt to exist in the boundary box, but not outside.

    The OnTriggerEnter fires when the object enters the trigger volume. The OnTriggerExit will only fire IF the object was first within the trigger volume, and leaves the volume (specifically, WHEN it leaves the trigger volume).
     
    Last edited: May 4, 2016
  49. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Do you have gravity turned on for you bolts?
     
  50. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    We are affecting velocity directly in space shooter and letting the physics engine move the ship. The physics engine is aware of time when moving an object with velocity and fixed update is regular so is called at even and exact intervals, whereas update is dependent upon the amount of processing done in a scene - so the change in time (delta time) will vary from update frame to update frame.

    In roll a ball we are adding force to the ball and how much force depends upon how much time has elapsed between frames. The physics engine takes the force and calculates the velocity of the rigidbody, and then the physics engine moves the ball.

    In space shooter, we're just doing that last velocity step directly.