Search Unity

Infinite Runner Starter Pack

Discussion in 'Assets and Asset Store' started by opsive, May 23, 2013.

  1. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,127
    Does your model expose the head bone? You could parent it to that game object.
     
  2. areszues92

    areszues92

    Joined:
    Dec 16, 2013
    Posts:
    78
    I'm currently using your character model for testing.
     
  3. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,127
    In that case you could try parenting it with this game object:

    $head.PNG
     
  4. areszues92

    areszues92

    Joined:
    Dec 16, 2013
    Posts:
    78
    Tried that, the camera points to the ground. Tried parenting to "MCH-head_socket2", it works but I have to manually drag the Main Camera to it when the game starts.
     
  5. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,127
    The scripts assume that the camera isn't parented by anything so you'll have to modify the scripts a little bit. Do you want it to start out in first person even at the main menu? If that is the case you may be able to get away with completely disabling the Camera Controller - this will work if you want the camera to not do any tracking of its own.
     
  6. areszues92

    areszues92

    Joined:
    Dec 16, 2013
    Posts:
    78
    I think I'll just stick to positioning the camera on the character's head in the Player Controller script.
     
    Last edited: Mar 30, 2014
  7. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,127
    You could do that or an easy way would be to change Camera Controller to the following:

    Starting with line 76 change the following (within startGame):
    Code (csharp):
    1.  
    2.         } else {
    3.             thisTransform.parent = playerTransform.FindChild("CharacterRig/root/MCH-head_socket2"); // this should probably be a variable
    4. ...
    5.         }
    6.  
    Then remove the entire else block starting with line 133:
    Code (csharp):
    1.  
    2.         } else {
    3.             Vector3 currentVelocity = Vector3.zero;
    4. ..
    5.             thisTransform.rotation = Quaternion.RotateTowards(thisTransform.rotation, relativeTargetRotation, rotationSpeed);
    6.         }
    7.  
    becomes
    Code (csharp):
    1.  
    2.         }
    3.  
    That's all it takes. Then you should modify the in game position to fit the transform of the character's head and you're good to go. Here's what it looks like with a in game position of (0,1.8,0.2):

    $fps.PNG
     
  8. areszues92

    areszues92

    Joined:
    Dec 16, 2013
    Posts:
    78
    Will try, thanks.
     
  9. areszues92

    areszues92

    Joined:
    Dec 16, 2013
    Posts:
    78
    Opsive, in your readme, do I bake the renderer or lights? I have this problem.
     

    Attached Files:

    Last edited: Apr 1, 2014
  10. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,127
    You bake using lights. To bake the lightmapping of all of the infinite runner scene objects, bring all of the scene objects into the Unity scene. Spread them out so one lights don't affect another objects lights, then hit bake. Make sure after it is baked you apply the changes to the prefab (after returning the scene objects to their original position). Since the startup objects are made into a prefab and Unity doesn't support prefab hierarchies, you'll have to drag the new prefab into the startup prefabs as well.
     
  11. StephenAS

    StephenAS

    Joined:
    Mar 12, 2014
    Posts:
    16
    Hey Opsive,

    Does the turn scenery need to be square? I was tying to make them rectangular, so that when the player turns they don't run the chance of running into obstacles immediately, but I'm running into issues where the next platform is auto generating at the "height" distance away, so the platforms are progressively away from the scenery as the sections change. By section 4 the scene is overlapping the platform. Suggestions?
     
  12. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,127
  13. StephenAS

    StephenAS

    Joined:
    Mar 12, 2014
    Posts:
    16
    So based on the post I started messing with the Platform Object offset to fix the issue, but the next platforms seem to be ignoring the override size.

    I set the T section's override to 28 and 14, but the Inside Straight (which i haven't changed at all) is just putting them in the middle like the t section doesn't exist, which you see can in the screenshot.

    $TplatformIssue.PNG
     
  14. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,127
    If you decrease the depth (z) of the both turn does the road move closer to the straight platform?
     
  15. StephenAS

    StephenAS

    Joined:
    Mar 12, 2014
    Posts:
    16
    It does, which makes sense. Pictured below,
    $TplatformIssue2.PNG

    Sorry I should have stated that the platforms over it were the issue, not the one below (I selected this platform so you could see it in the screen below).
    $TplatformIssue3.PNG
     
  16. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,127
    Ah so the two inside straight platforms are causing the issue? Try increasing the x center offset on the both turn.
     
  17. StephenAS

    StephenAS

    Joined:
    Mar 12, 2014
    Posts:
    16
    That was it, thanks!
     
  18. areszues92

    areszues92

    Joined:
    Dec 16, 2013
    Posts:
    78
    I did exactly what you said, but when the game starts, the textures and lights are messy. In the lightmapping window, do I choose the All or Lights scene filter?
     
  19. Dharma_raj

    Dharma_raj

    Joined:
    Jun 21, 2013
    Posts:
    109
    Hi Opsive,

    1. How can we make a 4 way junction turn. Straight, left and right. Also each turn should takes us to a new section.
    2. How can we randomize the distances of each section in linear mode?

    Thanks
     
    Last edited: Apr 2, 2014
  20. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,127
    @areszues92 -

    Are the baked lights messed up for every single scene file or just the startup objects? For the lightmapping settings you shouldn't have to change anything if you want to use the exact settings that I did. I am unsure where the All or Lights scene filter is, here are the options that I used:

    $lightmapping.PNG

    @Dharma_raj

    1. Currently you can't. I will be starting on version 1.6 in a few weeks and that is one of the main features that I plan on adding. For the each turn going to a new section, that one is going to take some modification within the InfiniteObjectGenerator. Within InfiniteObjectGenerator:platformSpawned you can manually change the section when a turn is spawned. It is going to take a little bit of work to get the section to persist though because sectionSelection.getSection will ignore the changes that you made after a turn has spawned. You'll need to modify that class as well.

    2. This is also going to take some custom programming. Within SectionSelection:start you could generate random distances before the DistanceValueList:init method is called for both the platform and scene sections.
     
  21. areszues92

    areszues92

    Joined:
    Dec 16, 2013
    Posts:
    78
    @opsive, It's ok now. I didnt drag out all the scene files, I did it one by one. It seems if I just take one scene file and bake the lights, it messes with the other scene files.
     
    Last edited: Apr 2, 2014
  22. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,127
    Great to hear. Yeah it is a pain to do but luckily you really only have to do it once. It would have been nice if newer versions of Unity would support older versions of the lightmap files but since it is a one time thing it isn't terrible.
     
  23. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,462
    Would love to see these two features implemented in a 1.6

    Great stuff.
     
    Last edited: Apr 2, 2014
  24. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,127
    Thanks for letting me know rocki, it's always good to know a new feature that I am working on will actually be used by somebody. Which two features are you talking about? The four way split and random distances within the linear section?

    To give some more details on the platform turns, the first feature that I plan on adding is the four way split. Then I'd like to be able to support non-90 degree turns. If enough people are using the curve feature I'd then like to expand on that by allowing a T turn contain two curves: one for going left, the other for going right.
     
  25. areszues92

    areszues92

    Joined:
    Dec 16, 2013
    Posts:
    78
    Opsive, how do I make an ammo counter, e.g. on the bottom right corner, it'll show 10/100, with every shot it decreases and pickups increases it.
     
  26. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,127
    The projectile attack feature has no concept of ammo so that's going to have to be custom code. In the projectileManager you can add an ammo field and then show that from the GUI manager, for example:

    Code (csharp):
    1.  
    2. public int ammo;
    3.  
    Code (csharp):
    1.  
    2. public bool canFire()
    3. {
    4.    return ammo > 0  fireTime + reloadTime < Time.time;
    5. }
    6.  
    Then when it fires:

    Code (csharp):
    1.  
    2.     public void fire()
    3.     {
    4.         if (canFire()) {
    5.             fireTime = Time.time;
    6.             ammo--;
    7.             ...
    8.  
    For showing it within the GUI, take a look at how the score is shown and it will be very similar to that. To replenish the ammo with a pickup you'll have to create a new collidable object and when that is collected you get an instance to the projectile manager and increase the ammo count. The power up object will provide a rough example of how that works.
     
  27. areszues92

    areszues92

    Joined:
    Dec 16, 2013
    Posts:
    78
    Thanks, will try.
     
  28. PrisonerOfLies

    PrisonerOfLies

    Joined:
    Dec 6, 2013
    Posts:
    105
    i realised the loop section loops the distance back to 0, hence how can i make a rule that goes like section 0, 1, 2, 3, 4, 3, 4, 3, 4, ....
     
  29. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,127
    There is an option within the editor that allows you to specify which section to loop back to:

    $section.PNG
     
  30. PrisonerOfLies

    PrisonerOfLies

    Joined:
    Dec 6, 2013
    Posts:
    105
    i put loop back to section 3 but when i tested it all that spawn is the normal straight platform, i assume the distance got resetted to zero.
     
  31. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,127
    Very good catch.. This bug has existed ever since I put the loop back to feature in on August 21 - I guess you're the first person to really use it.

    I'll send you a PM with the changed files.
     
  32. InitoryDad

    InitoryDad

    Joined:
    Jul 3, 2012
    Posts:
    21
    Justin, I have found this question, send me when you change file, too, pls. lijianxin@me.com
     
  33. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,462
    Yes, the 4 way split and the random distances within the linear section.

    Non-90 degree turns is also super cool to have. Having these variations will make the game much more interesting.
     
    Last edited: Apr 3, 2014
  34. Dharma_raj

    Dharma_raj

    Joined:
    Jun 21, 2013
    Posts:
    109
    Thank you so much for the information. Awaiting for the v1.6.
    Let me try the random distances as you suggested.

    Also please see how can I get the following thing done. I have a special power up, say like Bull ride in Stampede run, in which we(the bull) can break all obstacles. So obviously we need more obstacles to get spawned down the track. The question is how could I spawn more obstacles on collecting the power up? If the player collect the ride powerup the platform should spawn additional obstacles to it else the obstacle remains same. I know we can make use of the Collidable position of platform object script by increasing it. But will it work dynamically on collecting the power up.


    Thanks
    Dharma
     
  35. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,127
    @iamjianxin -

    Email sent.

    @Dharma_raj -

    The problem with dynamic object generation is that it is very game specific and I haven't figured out a good way to generalize that to put in the pack. In your case I would modify the Infinite Object Manager so it increases the probability that an obstacle will be spawned. On line 347 of InfiniteObjectManager.cs you would add something like:

    Code (csharp):
    1.  
    2.             ...
    3.             if (objectType == ObjectType.Obstacle  PowerUpManager.instance.isPowerUpActive(PowerUpType.YourPowerUp)) {
    4.                 probabilityCache[objectIndex] *= SomeConstant
    5.             }
    6.             ...
    7.  
    Where YourPowerUp is the power up that affects the obstacle spawns and SomeConstant is a multiplier that will increase the probability that an obstacle is spawned.
     
  36. areszues92

    areszues92

    Joined:
    Dec 16, 2013
    Posts:
    78
    My programming is bad, tried but I couldn't get the ammo variable to increase. I'm using the coins as ammo for testing.
     
  37. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,127
    What did you try?
     
  38. areszues92

    areszues92

    Joined:
    Dec 16, 2013
    Posts:
    78
    I tried linking collecting the coins to increase the ammo variable, but it didnt work.
     
  39. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,127
    Can you post what code you changed so I can see what went wrong?
     
  40. areszues92

    areszues92

    Joined:
    Dec 16, 2013
    Posts:
    78
    I added the code you posted, and then in CoinObject script, I added this.

    Code (csharp):
    1. private ProjectileManager projectileManager
    Code (csharp):
    1. public void collectCoin()
    2.     {
    3.          ......
    4.          ProjectileManager.instance.ammo +=1;
    5.     }
    Then it gave me, NullReference error.
     
    Last edited: Apr 4, 2014
  41. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,127
    ProjectileManager isn't a singleton object so you'll have to get a reference the the instance of it instead. Try:
    Code (csharp):
    1.  
    2. PlayerController.instance.GetComponent<ProjectileManager>().ammo += 1;
    3.  
    Of course, you'll want to cache the Projectile Manager instance but that should at least get you started.
     
  42. areszues92

    areszues92

    Joined:
    Dec 16, 2013
    Posts:
    78
    Thanks, it worked. Now, with every shot I want to decrease the GUI coin count but the setInGameCoinCount() only accepts a number.
     
  43. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,127
    You can change that to a string:

    Code (csharp):
    1.  
    2. public void setInGameCoinCount(string value)
    3.  
     
  44. areszues92

    areszues92

    Joined:
    Dec 16, 2013
    Posts:
    78
    I mean I could only put
    Code (csharp):
    1. guiManager.setInGameCoinCount(0);
    , how do I make it -=1?
     
  45. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,127
    I don't follow. The GUIManager only displays what you tell it to display, it doesn't keep a count of anything. setInGameCoinCount sets a UILabel which will then show on the GUI. It is probably your best bet to just add a new UILabel to the GUI and use it specifically for ammo since that is your end goal anyway.
     
  46. areszues92

    areszues92

    Joined:
    Dec 16, 2013
    Posts:
    78
    I'm just using the Coins UI to test the code. How do I make the coin count decrease by 1 with each shot?
     
  47. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,127
    You would just set it to the amount of ammo that is left:

    Code (csharp):
    1.  
    2. var ammo = PlayerController.instance.GetComponent<ProjectileManager>().ammo;
    3. guiManager.setInGameCoinCount(ammo);
    4.  
     
  48. areszues92

    areszues92

    Joined:
    Dec 16, 2013
    Posts:
    78
    Thanks, got it working. Using "PlayerController.instance.GetComponent<ProjectileManager>().ammo;" uses up more resources, any side effects?
     
  49. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,127
    If you access the same object reference multiple times in general it is not a good idea to use GetComponent because GetComponent does a search for that component. To prevent it just cache the reference. For example put this within the Awake method:
    Code (csharp):
    1.  
    2. projectileManager = PlayerController.instance.GetComponent<ProjectileManager>();
    3.  
    I saw that you already declared projectileManager at the top of the file. Then when you increment the ammo all you need to do is
    Code (csharp):
    1.  
    2. projectileManager.ammo++;
    3.  
     
  50. areszues92

    areszues92

    Joined:
    Dec 16, 2013
    Posts:
    78
    Thanks, working nicely.
     
    Last edited: Apr 5, 2014