Search Unity

Space Shooter Tutorial Q&A

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

  1. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    morning @Wellfooled,

    just wondering, you dont have two colliders attached to your asteroid prefab do you? highlight the prefab and check the inspector to see if theres just one there.

    on the last AddScore function.

    AddScore() is a public function within your GameController script, and therefore accessible to other scripts as long as they have a reference to that GameController object instance. so other things can use it basically.

    in your DestroyByContact script within the start() function gameController is found and populated.
    also in that script at the top you have declared an INT value for scorevalue.

    so once the OnTriggerEnter() is called, this script can access the AddScore() public function of the gameController by using the dot operator. and pass to it the scoreValue.
    Code (CSharp):
    1. gameController.AddScore (scoreValue);
    breaking that last block you wrote down
    Code (CSharp):
    1. public void AddScore (int newScoreValue)
    this function requires an INT type to be passed into it, the newScoreValue is were it temporarily stores the value for use in this function only. so as long as you give it an integer value its fine.
    Code (CSharp):
    1. {
    2.         score += newScoreValue;
    this is just a shorthand way of saying score = score + newScoreValue, ie add what you have passed in to the total score.
    Code (CSharp):
    1. UpdateScore ();
    2. }
    and this line calls the UpdateScore() function, that displays the score.
     
    schwab likes this.
  2. AlbertoNieto

    AlbertoNieto

    Joined:
    Apr 14, 2015
    Posts:
    4
    Thanks both @christinanorwood and @Westyfu.

    I have a new problem now. When I fire the bolt and it impacts on the asteroid, instead of destroying it it pushes it back:


    I can see the explosion if I run into it with my ship, though.
     
    Last edited: Apr 14, 2015
  3. christinanorwood

    christinanorwood

    Joined:
    Aug 9, 2013
    Posts:
    402
    For the Bolt prefab's capsule collider have you checked Is Trigger?
     
    OboShape likes this.
  4. AlbertoNieto

    AlbertoNieto

    Joined:
    Apr 14, 2015
    Posts:
    4
  5. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    This needs to be looked at in the context of the function being called. You will have both:
    Code (CSharp):
    1.    public void AddScore (int newScoreValue)
    2.     {
    3.         score += newScoreValue;
    4.         UpdateScore ();
    5.     }
    and
    Code (CSharp):
    1.     void UpdateScore ()
    2.     {
    3.         scoreText.text = "Score: " + score;
    4.     }
    So, when AddScore(int newScoreValue) is called from another component, the function takes the current score, being held in the int variable score and adds to it the value held in newScoreValue. The operator += indicates both a value to add and the final summation. It is sort-hand for score = score + newScoreValue, so score plus equals newScoreValue.

    Does this make sense?

    Then, the next line in AddScore is UpdateScore(); which calls the function void UpdateScore() below.

    This function, UpdateScore(), the takes the scoreText variable, finds the text property and sets the value of that text property to the string value of "Score: " + score where "Score: " is a set string value and score is an int value. In this case the compiler is being clever. It has rules that say if I'm adding a numerical value to a string, I will automatically convert that numerical value to a string. SO, count is converted automatically from int to string. If you didn't have the leading string value, you would have to explicitly convert the numerical value to a string with ToString() like this:

    Code (CSharp):
    1. scoreText.text = score.ToString();
     
  6. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Not sure what's going on. Double check your steps against the video and the items against the "Done" scene.

    gameController.AddScore(scoreValue); seems to be called twice on occasion. Do you have an extra collider somewhere?

    Do you have any more information for us?
     
  7. Wellfooled

    Wellfooled

    Joined:
    Feb 23, 2015
    Posts:
    6
    You were both right. I spent so much time looking through the code for a mistake, I didn't even think to check for an out of place component >< I had a collider on both the parent and child of the asteroid prefab. Once I removed the extra the scoring works perfectly, thank you both!

    This makes way more sense once I understand the shorthand going on (I was wondering why it needed both + and =...I spent a few minutes testing out what would happen if I just had one or the other. The results weren't pretty). Thanks to you both again, OdoShape, Adam Buckner. This is all much less daunting with a little outside help, I appreciate it.

    But I'm still confused about the newScoreValue int. I don't think newScoreValue appears anywhere else in the code besides in this area (unlike, say score, which I set to 0 during void start) , how does it know what the value being held by it is?
     
  8. Westyfu

    Westyfu

    Joined:
    Mar 30, 2015
    Posts:
    16
    This is one of the things that got me thinking too.

    We never See or use newScoreValue like we do with Score so it's purpose is kinda lost on me.

    I put a restart (Respawn) loop into mine so that the Application doesn't reload the entire level, and displays a HighScore inside the Score text when no player is spawned.

    To follow along with one of the tutorials around the net, I had to change my Ints to Floats and got me thinking of it as a 'temporary container', I am probably WAY off here...

    What really stumps me is how does newScoreValue ever acquire a value to store, and from where?

    or is it always 0?

    Making score = score+0?
     
  9. AlbertoNieto

    AlbertoNieto

    Joined:
    Apr 14, 2015
    Posts:
    4
    Just a quick note.

    With Unity 5, audio.Play (); becomes GetComponent<AudioSource>().Play();
     
  10. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Ah, yes. I'll add that to the notes in the original post. Pretty much all "helper shortcuts" for components are depreciated except for "transform" and, I believe, "gameObject".
     
  11. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Don't. Please don't!

    The ints are ints we set for a reason. They contain whole numbers: 1, 3, 56, 489, 914857, whereas floats are for "decimal" numbers: 0.00001, 23.134, 23909876545678.0000000001.

    We wouldn't change a camera variable to a rigidbody variable, just to follow along with a different tutorial would we?

    Now, tbh, you will probably "get away with it" as you are starting with a value of 0.0f and adding 10.0f to the score each time, so you probably won't see any divergence from whole numbers... but you should find a way to refactor the code from the other tutorial into using ints, rather than using floats in our code... unless your hazards are "worth" partial points, like say, 10.23.
     
  12. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Morning @Westyfu, have a watch through the 'variables and functions' and 'scope and access modifiers' lessons in the tutorial section, should give you an idea on whats happening.

    variables and functions
    http://unity3d.com/learn/tutorials/modules/beginner/scripting/variables-and-functions

    scope and access modifiers
    http://unity3d.com/learn/tutorials/modules/beginner/scripting/variable-scope-and-access-modifiers

    if you get a chance, get a look through the tutorials in the learn section, theres alot of good stuff there :)
     
  13. Westyfu

    Westyfu

    Joined:
    Mar 30, 2015
    Posts:
    16
    Cheers OboShape!

    I changed it because I wanted Scores to eventually have decimals like mentioned, So a hazard of a certain type would give a fractional value rather than a whole.

    edit: The Scope and Access tutorial helps a lot, thank you!
     
    Last edited: Apr 15, 2015
  14. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Variables and Scope (aka: What to do with "newScoreValue")
    The empty container things is not at all inaccurate, and some of these are temporary.

    What we are dealing with here is a matter of "scope": http://en.wikipedia.org/wiki/Scope_(computer_science)

    Let's take this code for example:
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class GameController : MonoBehaviour
    5. {
    6.     public float count;
    7.  
    8.     void Upadate () {
    9.         float getHorizontal = Input.GetAxis ("Horizontal");
    10.         SomeFunction (getHorizontal);
    11.         if (Input.GetKeyDown ("space")) {
    12.             Debug.Log (count.ToString ());
    13.         }
    14.     }
    15.  
    16.     void SomeFunction (float newValue) {
    17.         count += newValue;
    18.     }
    19. }
    There are three variables here: count, getHorizontal and newValue. They each have a different scope. We can see here, where we declare them:
    Decalred.jpg

    The scope of count allows it to be used throughout the script. It's declared at the top of the script, and can be used in any function within the script/class. Here we can see that it's working in both Update() and SomeFunction():
    Used.jpg

    The variable getHorizontal is declared/created inside Update, so therefore can only be used inside update. It lives and dies inside the Update function:
    Used2.jpg

    Now, to the variable newValue... This variable is created as part of a parameter list in the signature of the function. This is also a variable whose scope is contained by the function that declared it, but it has a specific and particular behaviour: To define they type of data/objects/things being passed into the function. We send items to functions as arguments. These arguments must match the type of the parameters in the parameters list and there needs to be exactly the same number of arguments as there are parameters*. In the case of this sample code, we are sending a float value as an argument - this is the float value we get from Input.GetAxis ("Horizontal") and is saved in the float variable getHorizontal - and that float value is received by the function SomeFunction, where it is declared in the parameters list, and used only within the scope of the function SomeFunction. This way, we can pass the value of the float variable getHorizontal, gathered in Update, into another function. We are not, however, moving the variable... just the value of that variable.
    Flow.jpg

    So - in the case of:
    Code (CSharp):
    1.     public void AddScore (int newScoreValue)
    2.     {
    3.         score += newScoreValue;
    4.         UpdateScore ();
    5.     }
    We are accessing AddScore from another script, as it's a public function. When we access this function, we are sending a value as an argument that matches this function's parameters list:
    Code (CSharp):
    1. playerController.AddScore (myHazardValue);
    :

    So: int newScoreValue is being used only inside AddScore, due to its scope, and the value can be any int value, where the value is set by the code calling this function.

    Make sense?

    -

    *There are ways to write a parameters list to allow an unspecified number of argument, but that's beyond the scope of this post.
     
    Wellfooled and OboShape like this.
  15. Westyfu

    Westyfu

    Joined:
    Mar 30, 2015
    Posts:
    16
    It does now I have an understanding of Scope!

    One of the things I've not stumbled into yet, thank you!
     
  16. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    One note: When you are coding, it is considered best practice to contain scope as much as possible and declare variables only where they are needed. This is why the following is considered BAD CODE:

    Code (CSharp):
    1. public Rigidbody rb;
    2. private float getHorizontal;
    3. private float getVertical;
    4.  
    5. void Update () {
    6.      getHorizontal = Input.GetAxis ("Horizontal");
    7.      getVertical = Input.GetAxis ("Vertical");
    8.      Vector3 move = new Vector3 (getHorizontal, 0.0f, getVertical);
    9.      rb.AddForce(move);
    10. }
    The scope of these variables allows them to be used in all functions within the class, which leads to more BAD CODE:

    Code (CSharp):
    1. public Rigidbody rb;
    2. private float getHorizontal;
    3. private float getVertical;
    4.  
    5. void Update () {
    6.      getHorizontal = Input.GetAxis ("Horizontal");
    7.      getVertical = Input.GetAxis ("Vertical");
    8.      Vector3 move = new Vector3 (getHorizontal, 0.0f, getVertical);
    9.      rb.AddForce(move);
    10. }
    11.  
    12. void Oops () {
    13.      getHorizontal = 100.001f;
    14. }
    We don't want to have access to certain variables to prevent any possibility of using them inappropriately, so - we only declare them with the scope they need to be used in.
     
  17. Zamas

    Zamas

    Joined:
    Apr 15, 2015
    Posts:
    35
    Hi all.

    I am currently working on this tutorial and I have a small issue in part 10.

    My bolts don't make contact with the asteroid. I mean they don't seem to trigger the OnTriggerEnter for destruction.

    I can see them go through the asteroid but without result.

    I checked and both the bolt and the asteroid collider are "is trigger".

    I also didn' have the boundary object and the asteroid disapearing like in the tuto. I guess those two issues are linked.

    Where should I look ?

    Edit : Well, problem solved. I deleted my asteroid Object and made a new one and everything is fine. I don't know where the problem came from, but I suspect the isTrigger of the asteroid. I think it was on in my previous attempt but it's off in the working one. I'll need to take a deeper look at what isTrigger do.
     
    Last edited: Apr 16, 2015
  18. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Great! Glad you got it to work out.
     
  19. Zamas

    Zamas

    Joined:
    Apr 15, 2015
    Posts:
    35
    I still have a few issues.

    I realized that all my asteroid where not on the same Y axis than the ship and bolts. Resulting in them not getting destroyed like they should. They were also disappearing without explosion. Those two problems are in fact linked. Due to the Y axis movement my asteroid get ouside the boundary field and activate the onTriggerExit of the boundary. And so they disappear without an explosion.

    Although I found a solution to force the Y position to stay at 0, I cant find where does that initial movement comes from. And I would rather get rid of the few lines of code I used to fix them.

    My second issue is with my bolts. After looking at them in the scene view, it appears that they have a rotation on there X axis. But I don't remember ever applying a modification to their rotation transform.

    Edit : Forget the part about the bolt rotation. I found where it's coming from. When the ship tilt, so does the GameObject spawning the bolt. And since we apply the "spawner" rotation to the bolt (if I remember right), they rotate too.
     
  20. wolf3r

    wolf3r

    Joined:
    Apr 11, 2015
    Posts:
    9
    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.  
    10. public class PlayerController : MonoBehaviour
    11. {
    12.     public float speed;
    13.     public Boundary boundary
    14.  
    15.     void FixedUpdate ()
    16.     {
    17.         float moveHorizontal = Input.GetAxis ("Horizontal");
    18.         float moveVertical = Input.GetAxis ("Vertical");
    19.  
    20.         Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
    21.         Rigidbody.velocity = movement * speed;
    22.  
    23.         Rigidbody.position = new Vector3
    24.             (
    25.                 Mathf.Clamp (Rigidbody.position.x boundary.xMin boundary.xMax),
    26.                 0.0f,
    27.                 Mathf.Clamp (Rigidbody.position.z boundary.zMin boundary.zMax),
    28.             );
    29.     }
    30. }
    Getting 3 errors:
    Assets/_Scripts/PlayerController.cs(15,12): error CS1519: Unexpected symbol `void' in class, struct, or interface member declaration
    Assets/_Scripts/PlayerController.cs(25,74): error CS1526: A new expression requires () or [] after type
    Assets/_Scripts/PlayerController.cs(25,88): error CS1525: Unexpected symbol `boundary'
     
  21. Zamas

    Zamas

    Joined:
    Apr 15, 2015
    Posts:
    35
    1° - You forgot a ";" at the end of you Boundary variable.
    2° - try removing the last "," on line 27
     
  22. wolf3r

    wolf3r

    Joined:
    Apr 11, 2015
    Posts:
    9
    New code:
    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.  
    10. public class PlayerController : MonoBehaviour
    11. {
    12.     public float speed;
    13.     public Boundary boundary;
    14.  
    15.     void FixedUpdate ()
    16.     {
    17.         float moveHorizontal = Input.GetAxis ("Horizontal");
    18.         float moveVertical = Input.GetAxis ("Vertical");
    19.  
    20.         Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
    21.         Rigidbody.velocity = movement * speed;
    22.  
    23.         Rigidbody.position = new Vector3
    24.             (
    25.                 Mathf.Clamp (Rigidbody.position.x boundary.xMin boundary.xMax),
    26.                 0.0f,
    27.                 Mathf.Clamp (Rigidbody.position.z boundary.zMin boundary.zMax)
    28.             );
    29.     }
    30. }
    Errors:
    Assets/_Scripts/PlayerController.cs(25,88): error CS1525: Unexpected symbol `boundary'
    Assets/_Scripts/PlayerController.cs(25,74): error CS1526: A new expression requires () or [] after type
     
  23. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    @wolf3r have a look at your lines 23 - 28.
    where you are using Mathf.Clamp() you are missing the commas to separate the arguments out.

    Code (CSharp):
    1.         Rigidbody.position = new Vector3
    2.             (
    3.                 Mathf.Clamp (Rigidbody.position.x, boundary.xMin, boundary.xMax),
    4.                 0.0f,
    5.                 Mathf.Clamp (Rigidbody.position.z, boundary.zMin, boundary.zMax)
    6.             );
    for reference,
    http://docs.unity3d.com/ScriptReference/Mathf.Clamp.html

    the scripting reference, and the manual are good place to look for info and details on scripting functions etc.

    and you have offline copies of them that come with the Unity installation :)
    I use them alot offshore when i dont have access to tinterweb.

    depending on your installation, they are roughly here..
    Unity\Editor\Data\Documentation\en\Manual\index.html
     
    Last edited: Apr 16, 2015
  24. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    This was correct. Remove the LAST comma, NOT ALL the commas!

    Don't give up! Coding is very finicky, and you need to pay strict attention to captalization and punctuation.
     
  25. Wellfooled

    Wellfooled

    Joined:
    Feb 23, 2015
    Posts:
    6
    That was an awesome read, thanks for taking the time to explain all of that! I think its making sense to me now.
     
  26. AtoSaizo

    AtoSaizo

    Joined:
    Apr 17, 2015
    Posts:
    1
    Hey y'all! I've recently started working in Unity in an attempt to make a scrolling shooter. This tutorial has been a great jumping off point, but I'm absolutely inexperienced when it comes to C# and Unity in general and my ambition is greatly outweighing my ability here. Hopefully you may be of assistance.

    So first of all, how would I set up different phases of hazards? For example, I'm wanting to have a wave of fairly easy enemies, then an asteroid field after that. After clearing the asteroids, more difficult enemies would appear, and possibly even lead to a boss. In this sense the tutorial is all one endless phase as asteroids and enemies until the player dies. How would I set up different phases and transition from one to the next?

    Additionally, what would be the best method of spawning enemies? The Done files with tutorial has them spawn somewhat randomly akin to the asteroids, but I'm wanting to give them defined movement patterns. The patterns themselves I can figure out with the Animation tool, but I'm not quite sure of the best way to go about spawning them and timing those spawns.

    Next, I'd like to add a power up system. From what I figure, I can create a powerup asset that would appear when a hazard is destroyed (via Instantiate), that then dies and gives power points to the player when they come into contact (via DeathByContact). For that to work, I'd need a system similar to the scoring system made in the tutorial and create different levels of power to activate at a given value. I imagine setting that up won't be too difficult, but how would program the upgrades activate after the set score is met (ex: upgrading from single fire to triple fire after 100 points are earned)?

    Similarly, I think a lives system would be a good addition as well. The player would start with two extra lives and earn extras after a set score value is met. This also doesn't seem terribly difficult, but I'm just unsure of how to go about setting it all up.

    I'm slowly making my way through this thread and its archived predecessor in hopes of learning what I can from others' questions since there's a lot of info in them, so sorry if these questions have already been asked and resolved. Thanks for any help you can give, I greatly appreciate it!
     
  27. Zamas

    Zamas

    Joined:
    Apr 15, 2015
    Posts:
    35
    For your different phase of hazard, I would suggest a loop just like the one used in this tutorial where you increment a new variable (waveLevel) after each wave. Then in your loop, you add "If" condition where you check "waveLevel", and depending on that variable, you can then launch a new wave with different ennemys.

    --> if waveLevel == 1 then wave1, if waveLevel == 2 then wave 2...

    Maybe there is a better way, for exemple using time as a trigger to change the wave type, or even a function dedicated ofr that in Unity.

    For your upgrade, same method. A new variable that you can use in your "shot" function. With that, you could change the shot with a "if", loading different game object apart from the bolt.

    And that is the same for each of your idea. If you have different things you want to use depending on certain condition, then you need to set up something to check if those conditions are satisfied. And for that you will need new variable/function to check/call using if/when/while/for...

    On my end I have a question. Is there video for adding ennemy ship or is it something to do on our own ?
     
  28. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Are you applying gravity to the asteroids? They could be falling out of the game area due to the effects of gravity.
     
  29. Zamas

    Zamas

    Joined:
    Apr 15, 2015
    Posts:
    35
    I don't think but I'll check. But if I remember, they were going slightly up and not down. Which rules out gravity. Still I didn't play much with that point today so I have no idea about where it's comming from. It shouldn't be physics since they're "isTrigger" and are destroyed on contact. I' try to do that part alone on a new scene to see if I can sort out that mystery.
     
  30. lavagin

    lavagin

    Joined:
    May 30, 2013
    Posts:
    2
  31. Zamas

    Zamas

    Joined:
    Apr 15, 2015
    Posts:
    35
    Must the asteroid be "isTrigger" ? Because in the tutorial it says that both the asteroid and the bolt are trigger collider but the asteroid isn't "isTrigger". I ask because I realized that when my capsule collider on my asteroid is not "isTrigger", then the asteroid Y transform goes from 0 to 1.3 (or something like that) at the start of the game. Which I think is why I had trouble with Asteroid not staying at Y = 0 yesterday.
     
  32. Prosperro

    Prosperro

    Joined:
    Apr 19, 2015
    Posts:
    4
    I really have no idea what this means. Everything was going fine with following the tutorial in the 1st "Rolling Ball" basics but now that I'm trying to understand how to follow an out dated Tutorial I am lost. Up until Video #6 I was able to figure out the subtle differences (turning off the lighting and selecting convex to see mesh etc) but is there a step by step explanation of the scripting to replace the dated tutorial for total beginners? I wish I understood what you meant by "create a variable to hold the reference, populate the reference in Start(), and use the reference variable to access this reference." Please help!
     
  33. Prosperro

    Prosperro

    Joined:
    Apr 19, 2015
    Posts:
    4
    Here is where the tutorial stops working for me on my newly purchased Unity 5. Lesson 6 when I enter the 1st script to move the ship I get back 3 errors. Here is the copied script I wrote as per the tutorial;

    using UnityEngine;

    using System.Collections;



    public class PlayerController : MonoBehaviour {

    {

    void FixedUpdate ()

    {

    float moveHorizontal = Input.GetAxis ("Horizontal");

    float moveVertical = Input.GetAxis ("Vertical");



    Vector3 movement = new Vector3 (moveHorizontal, 0,0f, moveVertical);

    Rigidbody.velocity = movement

    }

    }
     
  34. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    morning @lavagin
    do you have any of these folders listed in your project heriarchy when you attempt to open?


    or try another route and open up unity first, then go to Window > AssetStore and see if you can import the project from there.
     
  35. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    I know Adam and the learn team are working away behind the scenes get the info updated for these tutes, but until Adam gets back to you, you can try the following.
    your missing the end of line semicolon here, also theres a slight change to component access, if you change the line to the following it should work ok.
    Code (CSharp):
    1. GetComponent<Rigidbody>().velocity = movement;
     
  36. VilleP

    VilleP

    Joined:
    Apr 15, 2014
    Posts:
    2
    I recently watched the 6th tutorial, "Creating Shots", and I seem to be experiencing the problem with the bolt values. My bolts are getting a negative Y-value after I move them on the scene.

    I noticed that first the Y-value goes fast (in a couple of seconds, Z-value around 90 at Y-value -10) from 0 to around -10, after which it resets back to -1 and starts descending again. When reaching -10 again (in around 30 seconds, Z-value around 850 at Y-value -10), the value is reset again to 0, and starts descending very slowly, -0.000002 per second.

    I can't find the reason for this behavior. Gravity is not used. I can't think of anything the bolt would hit, although the background is at Y-value -10, which might be just a coincidence. But I noticed that the capsule collider has a different direction from the tutorial and seems to be correct when it is set to "Y-axis". I've attached a picture to show the values of my bolt and the behavior of the capsule collider. Included is also the script my bolt uses.

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class Mover : MonoBehaviour {
    5.     public float speed;
    6.  
    7.     void Start() {
    8.         Rigidbody rigidbody = GetComponent<Rigidbody>();
    9.         rigidbody.velocity = transform.up * speed;
    10.     }
    11. }
    Whether I use transform.up or transform.forward does not make a difference, it just reverses the values and the bolt is still veering into a wrong direction.
     

    Attached Files:

  37. Zamas

    Zamas

    Joined:
    Apr 15, 2015
    Posts:
    35
    Did you try creating a new one from scratch ? Do you get the same result ?

    Also why is your bolt rotated ? It's an empty GameObject, and therefor you don't have to do any rotation on it. The rotation is on your quad "VFX" (child item of your bolt GameObject).
     
    VilleP likes this.
  38. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Can you give us any more information? What do you mean "doesn't load up" are you not getting any files to Import? One option is to try using Windows/Asset Store from the in-editor menu, and searching from there.
     
  39. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Hummmm... I can't see why that is happening, off the top if my head. It could be that something is bumping them with a physical collision when the colliders are not isTrigger == true;

    I would just go back and redo the steps according to the lesson and see if that sorts it out.
     
  40. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    This is covered in the original post on this thread. Look at how the Rigidbody reference is cached, and try that in your project. If you still have questions, keep posting.
     
  41. Zamas

    Zamas

    Joined:
    Apr 15, 2015
    Posts:
    35
    That's what I did. And the same thing occured. And the only way to resolve this is enabling isTrigger on the boundary GameObject. At least it's the only way i found until now.

    Any idea of what I could do to get some logs ? I don't know what to log on the asteroid.
     
  42. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Please learn to use code tags:
    http://forum.unity3d.com/threads/using-code-tags-properly.143875/
     
  43. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664

    If you are getting errors, can you please post the errors? You can copy them from the lower part of the console after selecting them in the upper section.
     
  44. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Yes, and this is described in detail in the first/original post in this thread.
     
  45. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Are you sure you are not using gravity in anyway? Are the colliders isTrigger == true; ? You may have something twisted around and there could be local/global display mode issues. Make sure the orientations of all the GameObjects match the details in the video lessons. If in doubt, repeat the steps in the video and/or look at the "done" folder.
     
  46. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    You'd have to double check this against the videos and/or the done scene... but isn't it supposed to be set to isTrigger?
     
  47. Zamas

    Zamas

    Joined:
    Apr 15, 2015
    Posts:
    35
    I don't know. In the video the "isTrigger" case is not checked if I remember right. I'll check again.
     
  48. VilleP

    VilleP

    Joined:
    Apr 15, 2014
    Posts:
    2
    And I thought I went through all the values thoroughly... The rotation on the Bolt object was the cause for all my issues. I'm not sure why it caused the Y-value to behave like it did, but everything works now. Thank you for helping!
     
  49. blacktoy

    blacktoy

    Joined:
    Apr 22, 2015
    Posts:
    1
    Hello, I'm new to unity engine and C#. This is probably rather stupid question to you guys. As I begin to learn by example I notice that to build and compile the space shooter project require the uFrame framework from the asset store which is not free. But I'd rather to continue as I hoping I could find a way out. After chapter 6 "Moving the player" I've come to realize that there's nothing I could do with the imported assets if im not using the uFrame game framework. Please confirm this so I can get over it and moving on to another learn project.
    The error that I get is:
    Code (CSharp):
    1. Assets/Space Shooter For uFrame/SpaceShooterTutorial-uFrame/_DesignerFiles/MainDiagramControllers.designer.cs(15,7): error CS0246: The type or namespace name `UniRx' could not be found. Are you missing a using directive or an assembly reference?
    2.  
    3. Assets/Space Shooter For uFrame/SpaceShooterTutorial-uFrame/_DesignerFiles/MainDiagramControllers.designer.cs(135,54): error CS0246: The type or namespace name `Controller' could not be found. Are you missing a using directive or an assembly reference?
    4.  
    5. ...etc.
    It enlist to 25 error. And the code is:
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class PlayerController : MonoBehaviour {
    5.  
    6.     //public float speed;
    7.     public Rigidbody rb;
    8.  
    9.     void Start() {
    10.         rb = GetComponent<Rigidbody>();
    11.     }
    12.  
    13.     void FixedUpdate(){
    14.         float moveHorizontal = Input.GetAxis("Horizontal");
    15.         float moveVertical = Input.GetAxis ("Vertical");
    16.  
    17.         Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
    18.         rb.velocity = movement ; //* speed;
    19.     }
    20. }
    Thank you.

    [Updated]
    Sory. It seems like that I've downloaded the wrong assets. I've mistaken this one https://www.assetstore.unity3d.com/en/#!/content/25753
    which should be this one
    https://www.assetstore.unity3d.com/en/#!/content/13866
     
    Last edited: Apr 22, 2015
  50. Zamas

    Zamas

    Joined:
    Apr 15, 2015
    Posts:
    35
    Yeah the good asset package is the one published by Unity Technologies. You can filter all their package on the asset store.
     
    blacktoy likes this.