Search Unity

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

[RELEASED] PUN Rally

Discussion in 'Assets and Asset Store' started by perick, Dec 1, 2015.

  1. perick

    perick

    Joined:
    Jun 20, 2008
    Posts:
    235
    Asset Store link: https://www.assetstore.unity3d.com/en/#!/content/51082
    Link for YouTube Videos (part1, part2, part3, part4, part5)
    Bonus video: adding Edy's Vehicle Physics 5 to PUN Rally
    Demo versions:

    Android (new - unsigned APK);
    Mac
    Windows
    Linux

    The updated PDF tutorial can be downloaded for free HERE.

    We also have some free tutorials (moba in 24h, etc): Sertão Games' Blog

    [Original post]:
    Hi,

    PUN Rally is a complete base project for a multiplayer racing game using Photon, the most popular network platform for Unity. We're in the process of authorizing and releasing the project on the Asset Store. We put this thread together for collecting user feedback.

    The project includes all sources and a 30+ pages illustrated tutorial book (PDF) explaining its use of realistic physics, dead-reckoning, checkpoint-based positions, and several other important features of multiplayer games, such as lobby control, car-selection and server-synced race-start.

    Features:

    - Realistic physics based on standard colliders, wheel-colliders and rigidbody;
    - Detailed suspension movement;
    - Real-time race synchronization over the internet using PUN (Photon Unity Network);
    - Dead-reckoning techniques to smoothly deal with latency;
    - Server-synced start and grid spawns;
    - Checkpoint-based race management (positions, laps, finish, etc);
    - Custom car selection (prefabs based) for connected players;

    The project is a foundation for a multiplayer racing game, but also serves as a comprehensive introduction to several multiplayer concepts with Photon:

    - Dealing with lobbies, rooms creation and joining;
    - Managing player connection and disconnection (both in menus and races);
    - Using custom player properties;
    - Remote Procedure Calls (RPCs);
    - Server-based time/clock (for race start);
    - The PhotonView component;
    - Custom network synchronization of GameObjects;
    - PUNBehavior and Photon.MonoBehavior classes;

    Disclaimer: have in mind that PUN Rally is a complete base project, but not a fully featured game. It would need some additional scripts and art to be ready for release.

    We'd love to hear any comments or questions.

    pun-rally1.png pun-rally2.png pun-rally3.png pun-rally5.png
     

    Attached Files:

    Last edited: Feb 9, 2016
  2. b4c5p4c3

    b4c5p4c3

    Joined:
    Jan 4, 2013
    Posts:
    537
    Seems cool
     
  3. MikeUpchat

    MikeUpchat

    Joined:
    Sep 24, 2010
    Posts:
    1,056
    Looks cool and useful but would be a lot more interested if it used Unity network instead of Photon, any chance of a UNet version or could you explain why Photon was chosen over the new Unity networking system.
     
  4. perick

    perick

    Joined:
    Jun 20, 2008
    Posts:
    235
    Sorry for the late response, just saw this today.

    UNet is quite similar, and we might port and launch a UNet version in the future indeed.

    We chose photon because it's been used for quite some time already (and it works nicely), and they are publishing this tutorial for us.

    Most of the techniques used are usable on UNet as well, such as dead reckoning, checkpoints, etc.

    Thanks for the interest.

     
  5. slava_pankratov

    slava_pankratov

    Joined:
    Jan 17, 2015
    Posts:
    47
    Hi! Thanks for the package! Is there any demo or video available?
     
  6. perick

    perick

    Joined:
    Jun 20, 2008
    Posts:
    235
    Hi,

    I'm editing a video-tutorial this weekend. I'll put an executable demo available as well. I'll post the links here as soon as they're ready.
     
  7. perick

    perick

    Joined:
    Jun 20, 2008
    Posts:
    235
    [IMPORTANT] Just posting some clarifications in advance, based on some user questions we got from the publisher:

    - Remember to add both scenes to the build in File->Build Settings, otherwise the race scene won't load;
    - Setup an account for the free Photon Cloud service;
    - Get your app ID (from photon cloud), and set the following in the photon setup wizzard:
    - Service (photon cloud) and region (your choice);
    - your App ID;
    - Check "auto join lobby", otherwise the rooms won't appear for connected players;

    [Edit]: we're also releasing an updated version that don't required auto-join-lobby and has a much clearer function call order.

    Enjoy.
     
    Last edited: Dec 17, 2015
    tobiass likes this.
  8. perick

    perick

    Joined:
    Jun 20, 2008
    Posts:
    235
    Last edited: Dec 17, 2015
    naligator likes this.
  9. Justice0Juic3

    Justice0Juic3

    Joined:
    Apr 29, 2013
    Posts:
    188
    Argh (don't get me wrong, but) finally a PUN-driven racing game tutorial. :D
    Keep it up!!:)
     
  10. perick

    perick

    Joined:
    Jun 20, 2008
    Posts:
    235
    Got it right...:) Thanks. I love racing games, this is the reason I suggested this tutorial for them. You can get the Tutorial PDF for free and test the demos before buying the project, if you feel like doing so.
     
  11. ozgurhazar

    ozgurhazar

    Joined:
    Aug 30, 2014
    Posts:
    19
    Will you add any mobile control?
     
  12. perick

    perick

    Joined:
    Jun 20, 2008
    Posts:
    235
    I plan to test it with mobile in a few days (I'm using cross platform input already, so it won't be difficult to integrate the mobile input itself).

    [edited]: removed affirmation that PUN free doesn't work on mobile builds (it didn't work with Unity4, but it does with Unity5).
     
    Last edited: Dec 22, 2015
  13. michtek

    michtek

    Joined:
    Sep 11, 2012
    Posts:
    8
    Why i see start rooms? How closed rooms when race in progress?
     

    Attached Files:

  14. perick

    perick

    Joined:
    Jun 20, 2008
    Posts:
    235
    Do you have the updated version (1.0.4)? We just update with a few changes about an hour ago.

    Not sure if I understood the question: if you're asking how to close a room after you press start, we'll do an update including that, but you can do it by calling this when you start the race:
    PhotonNetwork.room.open = false;

    And also make sure you ignore closed rooms for the room list.

    So the method that is called from the GUI would look like this (it's in the PUNMenu.cs script):

    public void CallLoadRace() {
    PhotonNetwork.room.open = false;
    photonView.RPC("LoadRace", PhotonTargets.All);
    }

    And the IF inside the room listing method would be like this:

    if (index >= roomButtons.Length || !game.open)
    break;

    This will be on update 1.0.5 tomorrow (Dec, 18, 2015)
     
    Last edited: Dec 17, 2015
  15. Andreas12345

    Andreas12345

    Joined:
    Oct 17, 2013
    Posts:
    526
    In the demo i cannot choose a car for player 2
     
  16. perick

    perick

    Joined:
    Jun 20, 2008
    Posts:
    235
    Have you waited for the player to join BEFORE pressing start on the master-client (the one who created the room?)

    When you press start, you go to the race scene, and nobody is supposed to connect anymore (we're fixing this for the next update - see the other response above your question).
     
  17. perick

    perick

    Joined:
    Jun 20, 2008
    Posts:
    235
    I've just updated the demo binaries, so rooms won't be listed if already in race scene...
     
  18. stvster

    stvster

    Joined:
    Mar 4, 2013
    Posts:
    70
    Bought it.Like it. enough said.Well done and Thanx!
     
  19. perick

    perick

    Joined:
    Jun 20, 2008
    Posts:
    235
    Thank you (for the review as well). If you have any questions about the code or related stuff, feel free to ask.
     
  20. michtek

    michtek

    Joined:
    Sep 11, 2012
    Posts:
    8
    You add map selector in new update?
     
  21. perick

    perick

    Joined:
    Jun 20, 2008
    Posts:
    235
    Yes. We're creating a second (and maybe third) track. We'll have this option to demonstrate how to load different scenes (tracks) based on selection (instead of just a prefab, as it is with the car). We'll use ROOM custom properties for that.

    Our priority list for updates as of now:
    - Mobile controls (with cross platform input);
    - Scene/track selection with room custom properties;
     
  22. Andreas12345

    Andreas12345

    Joined:
    Oct 17, 2013
    Posts:
    526

    Ooops *working :)
     
  23. perick

    perick

    Joined:
    Jun 20, 2008
    Posts:
    235
    Hi Guys... Just released the first video (on a series of 5) that should help you into understanding the project. Here is the link: Photon Rally Tutorial

    Tomorrow we should have an update with the select track feature (haven't had time to solve the mobile input yet).
     
  24. stvster

    stvster

    Joined:
    Mar 4, 2013
    Posts:
    70
  25. perick

    perick

    Joined:
    Jun 20, 2008
    Posts:
    235
    [IMPORTANT]
    Guys, we decided to DELAY the 1.0.5 update for the following reasons:

    - I don't want to rush an update and risk having bugs during the holidays without doing a lot of testing (I'll be out of reach for 5 days);
    - You guys do have a nice working project right now...

    We'll finish the update before new year's eve, but the guys at Photon won't be able to send the update to Unity because of the holidays, so expect it to be available on the asset store only after Jan 4th, 2016.

    Some clarifications (we like to be transparent - some screenshots included at the end):
    - We do have two new tracks (for track selection), and the new GUI for that;
    - The new tracks are shorter (we thought the old one was way too long);
    - We'll keep the old one as a third track anyway;

    So, we'd like to ask for your comprehension. We're working hard on this new update, and it will include the following:

    - Track selector (3 tracks, each on a different scene);
    - Mobile input verified for Android devices;
    - Updated PDF tutorial with a new section on track selection;

    We'll also release Part 2 of the video series before new year's eve, and it will already include the discussion about the track selection feature.

    Thanks for all the interest and feedback, specially for those who bought the package, and for the ones who gave us such nice reviews. You can also contact us directly through our website.

    [Screenshots]

    Track selector:
    track-select.png

    Track 2 (easy and short):
    track2.png

    Track 3 (medium difficulty, with jump):
    track3.png

    Merry Christmas
     
    Last edited: Dec 22, 2015
  26. Justice0Juic3

    Justice0Juic3

    Joined:
    Apr 29, 2013
    Posts:
    188
    Hi, I just tried out the Windows demo and noticed the following:
    1. The car of which the packages comes with, is a bit slippery and bouncy. Can it easily be replaced with Unity's Standard Asset Car prefab? (Just in case to get that more solid and arcade-like feeling.)

    EDIT:
    2. The car won't reset after being flipped like so:
     
    perick likes this.
  27. perick

    perick

    Joined:
    Jun 20, 2008
    Posts:
    235
    [about the car prefabs]:
    We'll update the car a lot (we wanted it to be bouncy indeed...:)).

    The goal is to have you to play with the car parameters to achieve the behavior you want. There are other very good packages focused on standalone car physics (I personally recommend Edy's Physics Vehicles, which I do have and is awesome - but it does not include any network at all - ours is focused on multiplayer).

    If you do replace the car prefab for the one in Unity's Standard Assets, please make sure to replace the CarInput script for our custom version and to attach the NetworkCar, CarGUI and CarRaceControl scripts according to our prefabs.

    The synchronisation should work nicely for ANY car prefab you create, as long as it uses a rigidbody and our custom CarInput script. CarInput or any of our scripts can also be easily adapted to work with more complex car prefabs (such as the ones from Edy's pack).

    [flipped car]:
    Press left-shift to unflip (forgot to include a controls hint). It doesn't auto-unflip.

    Implementing an auto-unflip is easily done by checking if the car came to a stop (zero velocity) and the euler angles are in awkward values for X and/or Z local values. We might include this in a future update. We don't like to put too many features because it makes the code unnecessarily complicated, but we'll put this on the queue (second user to ask for it).
     
    Last edited: Dec 22, 2015
    Justice0Juic3 likes this.
  28. stvster

    stvster

    Joined:
    Mar 4, 2013
    Posts:
    70
    Hi,
    Which script would be the best place to put a disconnect and loadlevel(0) or(better yet just return to lobby still connected)
    with escape key.
    i.e.
    void Update() {
    if (Input.GetKey("escape"))
    Disconnect Code Here?(also I'm not certain of what the disconnect command is)
    Application.LoadLevel(0);
    }
    Thanx
     
    perick likes this.
  29. 99thmonkey

    99thmonkey

    Joined:
    Aug 10, 2012
    Posts:
    525
    Please make the car auto-unflip after set time (like 1 second). Please advise when all the tutorials will be up.

    Will you show how to make it so that everyone has a unique name (i.e. if everyone is called Bob, maybe it will say Bob1 or whatever number maybe the Networking ID).
     
    perick likes this.
  30. perick

    perick

    Joined:
    Jun 20, 2008
    Posts:
    235
    I suggest you create a separate script and disconnect from the room and the load the menu level (I'm typing from a cell phone, so I don't have the method name now. the method is documented in the PhotonNetwork class). Then you'll go back to the lobby only.

    But you'd need to update the menu script so it doesn't try to reconnect.

    Ill include this in next update.
     
    Last edited: Dec 23, 2015
  31. perick

    perick

    Joined:
    Jun 20, 2008
    Posts:
    235
    Hi. We'll include auto unflip indeed together with the other features.

    Nice tip to include the net Id if repeated names appear. We'll experiment the best way to do this for next update.

    As soon as I get back from Chile on 28th I'll film the second part of the video series (I'll keep posting here).

    Thanks for the feedback.
     
    Last edited: Dec 23, 2015
  32. perick

    perick

    Joined:
    Jun 20, 2008
    Posts:
    235
    Guys,

    I'm traveling to Chile for Christmas, so I'm not sure I'll be able to answer all questions during the next 5 days.

    I'll be back to full-steam work on 28th.

    Feel free to comment and ask anything.
     
  33. stvster

    stvster

    Joined:
    Mar 4, 2013
    Posts:
    70
    Happy Holidays perick (+ all) and have a safe trip.
     
    perick likes this.
  34. stvster

    stvster

    Joined:
    Mar 4, 2013
    Posts:
    70
    Thanx!
     
    perick likes this.
  35. Andreas12345

    Andreas12345

    Joined:
    Oct 17, 2013
    Posts:
    526
    I buy it when 1.05 is released.
    Sounds good here that perick give much feedback
    Thumbs up!
     
    perick likes this.
  36. emergki

    emergki

    Joined:
    Oct 15, 2007
    Posts:
    421
    Hi @perick , if I purchase your tutorial, do I need to purchase another Photon product in Asset Store?
     
  37. Andreas12345

    Andreas12345

    Joined:
    Oct 17, 2013
    Posts:
    526
    Playing with it:
     

    Attached Files:

    perick likes this.
  38. perick

    perick

    Joined:
    Jun 20, 2008
    Posts:
    235
    No, it should work fine with what's bundled (PUN free). Have you created a free account on Photonengine.com? Have you tested the tutorial on your machine?

    Feel free to ask any other question, and thanks for getting the pack.
     
    emergki likes this.
  39. perick

    perick

    Joined:
    Jun 20, 2008
    Posts:
    235
    It looks nice. Did you understand how to create the circular list of checkpoints, etc?
     
  40. Andreas12345

    Andreas12345

    Joined:
    Oct 17, 2013
    Posts:
    526
    Checkpoints are complete inspector driven!? Yeah it is easy.
     
  41. stvster

    stvster

    Joined:
    Mar 4, 2013
    Posts:
    70
    Hi,I have a Forum online that's just collecting dust and thought to use it here for developers to help test each others builds.May I post a link to it here where I'll explain in more detail?
    Thanx,
    Happy New Year
     
  42. emergki

    emergki

    Joined:
    Oct 15, 2007
    Posts:
    421
    I didn't purchased yet... I have another questions:

    Can it work with UnityCar physics?
    Works on mobile?
     
  43. perick

    perick

    Joined:
    Jun 20, 2008
    Posts:
    235
    1 - About UnitCar
    It is easy to adapt the solution to ANY car physics package, as long as you understand how it works. The two scripts that handle car synchronization (NetworkCar and CarInput) are small, and can be changed at will.

    I mentioned Edy's Physics Vehicles (another great car physics pack) above, that I personally like. However, I can't bundle it with these packages, and I chose to create PUN Rally using only the car scripts from Unity's Standard Assets because it would be easier for you to understand the tutorial and how everything works.

    What I can do in the future is put custom CarInput and/or NetworkCar scripts here in the forum that would work with these two packages (but it would have to wait for after the next update).

    2 - About mobile
    The scripts themselves work fine, but I'm still testing the CrossPlatform controls (mobile buttons for input) and it'd be part of the 1.0.5 update, due to early January.
     
    emergki likes this.
  44. perick

    perick

    Joined:
    Jun 20, 2008
    Posts:
    235
    Didn't understand why developers can't post links to their builds here. This is the official forum thread for the package and the only one I'll be supporting personally.

    Feel free to link to other posts if they are good to explain related subjects that are not directly part of PUN Rally such as:
    - alternative car physics packages;
    - networking guides (Photon or UNet or any other);
    - Race AI;
    - Anything I've forgotten...:)
     
  45. perick

    perick

    Joined:
    Jun 20, 2008
    Posts:
    235
    Good News!

    About implementation of update 1.0.5:

    Almost finished. The following requested features are implemented and tested:
    - Track selection (3 tracks now, each on a different scene - comments and PDF updated as well);
    - Mobile Input working (just needed to add the TiltControl prefab from the Standard Assets and tweak positioning, etc - the pack was already prepared for mobile in general);
    - Auto-unflip car (if car is upside down, it auto-unflips - code in on CarInput script, fully commented);
    - Computes and shows if car is going the wrong way;

    Maybe will still be included (not sure yet, still want to review code, comment more and make sure the above are easy to understand):
    - Adding numbers when players type same nickname in a room (Erick1, Erick2, etc);
    - Adding "back" button/key for returning to menu from race scene (leaving room, keeping nickname and photon connection);

    About release date of update 1.0.5:
    I still need to wait for the Photon guys to send the update to Unity (which will happen 1st week Jan, 2016), but the demos (now including Android APK) are already updated for the new version:

    Android (new - unsigned APK);
    Mac
    Windows
    Linux

    One remark about the mobile version:
    - I personally didn't like the controls on mobile. I believe "realistic" car physics are not suitable for mobile. A more "arcade" approach should suit it better, but this is out of scope of this tutorial/pack, so it'll be up to you to tweak car behaviour for your particular needs (there are many great packs on car physics out there, as we've been discussing);

    About the video series:
    - I'll capture part 2 of the video tutorial tonight and post the link here as soon as I finish editing.

    A screenshot of the demo running on Android (Motorola Moto X - 2 generation). We'll change the input buttons before the update is released:
    punrally-mobile.jpeg
     
    Last edited: Dec 28, 2015
    NeoUnity and Andreas12345 like this.
  46. perick

    perick

    Joined:
    Jun 20, 2008
    Posts:
    235
    Yep, they're inspector driven... This is what you need to create a fresh circular list of checkpoints for a new Track:

    - Each checkpoint is a game object with: 1) a collider (set as trigger), 2) the Checkpoint script;
    - The first checkpoint just after the Spawn points must be named Checkpoint1 (the race control script looks for it and sets a reference for it on each CarRaceControl);
    - The last checkpoint must have the "Is Start Finish" check enabled, telling the cars this is the checkpoint where laps/race end;
    - Set the references to form the circular list (drag Checkpoint2 as a reference on Checkpoint1, and so on...);
    - Pay attention to scale checkpoints to overlap the track from side to side, otherwise cars may miss them;

    Bonus (included in next update):
    Checkpoints can be used to compute if a car is going the wrong way...

    Compute the dot product between the car's transform.forward and the direction from the car to the next checkpoint (CarRaceControl keeps a reference to it on currentWaypoint). If the dot product is less than 0, the car is going the wrong way:


    Code (CSharp):
    1. // assuming this code is inside CarRaceControl
    2.  
    3. Vector3 correctDirection = currentWaypoint.transform.position - transform.position;
    4. if (Vector3.Dot(transform.forward, correctDirection) < 0) {
    5.     // car is wrong way - show message to player
    6. }
    That's it... The new update, due early January, will include three tracks, so it'd be easier to see how checkpoints are organized.
     
    Last edited: Dec 28, 2015
    NeoUnity likes this.
  47. NeoUnity

    NeoUnity

    Joined:
    Sep 4, 2013
    Posts:
    156
    I think it needs for modifying the script.
    - CarRaceControl.OnTriggerEnter()
    input.Steer = 0;
    input.Handbrake = 1;
    input.Steer = 0; ==> input.Accell = 0;
     
  48. perick

    perick

    Joined:
    Jun 20, 2008
    Posts:
    235
    You're right. Thanks. Fixed it here...
     
  49. stvster

    stvster

    Joined:
    Mar 4, 2013
    Posts:
    70
     
    perick likes this.
  50. Andreas12345

    Andreas12345

    Joined:
    Oct 17, 2013
    Posts:
    526
    What i like to see is after the package have all update s some addons like power ups and/ or weapons. For an example a remake of re-volt or something similar.
    I would pay for that. :)