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

[WIP] Super 23 Racing

Discussion in 'Works In Progress - Archive' started by Carwashh, Jun 27, 2015.

  1. Carwashh

    Carwashh

    Joined:
    Jul 28, 2012
    Posts:
    746
    I'm creating this post to show the progress of my latest game, get feedback, perhaps get a bit of a following ready for launch and hopefully get help when I'm stuck with certain aspects during development. I'll be trying to do an update at least once a week.

    Super23Racing-Title.png

    Super 23 Racing is a top down racing game, being developed for the PC (hopefully Steam) where players compete to earn points, money and unlock more tracks and cars. Points earn money, more points = more money, money is used to repair the player's car and purchase weapons.

    There are 4 cups to compete in, 3 include 5 tracks and the last cup includes 8 tracks (more to be added after launch, assuming all goes well). In between some tracks the player is taken to certain departments who will ask them questions, depending on the answers to these questions the player will receive extra money.

    I've shared a few videos of progress on my YouTube channel, here.
    The latest video embedded here


    To do (ever changing and not yet complete):
    • Cars
      • Tweak each car so their stats are different
    • Weapons
      • Everything
    • Cups
      • Cup Management
      • Cup names
    • Race Management
      • TBD
    • Game Manager
      • Track car unlock progress
      • Track cup unlock progress
    • Multiplayer (to do near the end of development)
      • Splitscreen multiplayer for 2, 3 and 4 players
    • Controls
      • Improve the control system to be more robust and customisable for up to 4 players
    • U.I.
      • Decide on an art style
    Done so far:
    • Cars
      • 14 car prefabs
      • Improved collision/ fix rotation on slopes
      • Added scriptable objects to manage the cars and their unique stats
    • Player Cars
      • Player can now fire forwards and backwards
      • Added respawning
      • Player can now select which car to use
    • A.I.
      • Movement around the track.
      • Checkpoints
      • Paths/ nodes
      • Enemies can now fire forwards and backwards
      • Added respawning
    • Characters
    • Added scriptable objects to manage the characters and their unique stats
    • Player can now select which character to use (currently has no in-game affect)
    • Race Management
      • Lap progress
      • Track car positions
      • Pass finishing positions over to the race finished screen
      • Finish creating the spawner, to place cars in the correct starting position
      • Create respawner, to place cars on the track when needed
      • Save finishing positions, and assign their points
      • Pass info to the cup manager
    • Camera
      • Make the camera dynamic, so that the player can see farther ahead depending on their direction
    • Environment
    • Improved the look of the water
     
    Last edited: Dec 12, 2016
  2. Carwashh

    Carwashh

    Joined:
    Jul 28, 2012
    Posts:
    746
    [Edit: The solution to this is to give the two axis, that aren't under player control, a lower value

    Code (csharp):
    1. goRigidbody.inertiaTensor = new Vector3(1e3f, 1e5f, 1e3f);
    ]

    In this video, you can see that when a car collides with something it rotates in an annoying/ unnatural way.

    It was suggested to me that I use
    Code (csharp):
    1. goRigidbody.inertiaTensor = new Vector3(1e5f, 1e5f, 1e5f);
    Which makes the collisions work great, if not perfectly, however this introduces another problem, the cars no longer rotate properly when going up/ down a slope.
    carnorotate.png

    I've only really tried upping the gravity (from -9 to -50), I'm lost at what else to try, would really like some input and assistance on this particular problem!
     
    Last edited: Jul 14, 2015
  3. IAmCraigSnedeker

    IAmCraigSnedeker

    Joined:
    Jul 20, 2014
    Posts:
    117
    Looks good! I've always liked top-down racing games
     
  4. Darkays

    Darkays

    Joined:
    Mar 31, 2013
    Posts:
    176
    Looks fun! The game seems to be on the right path.

    The physics do look a bit "floaty" and slippery in the video especially right in the beginning when the car is launched into the air. I don't think I can help you out with the physics problem as I really haven't messed with the physics system that much (most of the time I end up making custom physics, no need for complex physics in most of my games so far). I personally don't think that it is a good idea to change the gravity to fix the problem, I feel like there is a better way. Are the colliders on the car and track lining up correctly? Maybe an axis is being limited in a direction. Sorry I can't be of much help here.
     
  5. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    neat. These kind of games can be fun ... provided the control system works well and it doesn't turn into a frustrating nightmare trying to just get around the track... why is is the camera centered toward the bottom of the screen, rather than giving enough look-ahead distance?
     
  6. Carwashh

    Carwashh

    Joined:
    Jul 28, 2012
    Posts:
    746
    Thanks!

    Using 'inertiaTensor' fixes the floatiness, and crappy collisions, but then introduces the other issue mentioned. The rigidbody is setup correctly to allow for rotating on the axis - the issue only occurs when I'm setting 'inertiaTensor'.

    With the setup used in the video, it can be frustrating to get around the track, until I use 'inertiaTensor' then it becomes super fun.

    At the moment controls are simple and just wasd, but keeping the controls easy, intuitive and fun will be a focus - I'm planning to add support for control pads (Steam + XBox tested).

    As for the camera, I haven't done anything with that yet other than just set it up to follow the player and then gotten used to how it was. That obviously needs to be more dynamic, giving you more of a view ahead depending on which direction you're heading.
     
    Darkays likes this.
  7. Haagndaaz

    Haagndaaz

    Joined:
    Feb 20, 2013
    Posts:
    232
    looks like a fun game, would love to try a demo!
     
  8. Carwashh

    Carwashh

    Joined:
    Jul 28, 2012
    Posts:
    746
    Small update:

    - I fixed the issue I was having with cars going up hills, and edited the post in this thread with the fix.
    - I've now moved onto implementing some weapons, damage and respawning.

    Here's a new video of the weapons in development:


    I'm showing two bugs in this video.
    1- The wheels are left behind when a car is destroyed.
    Due to the hierarchy of the car models, the mesh collider is a child object three deep from the parent, so disabling GameObject didn't disable the entire car

    I was using this.
    Code (csharp):
    1. GameObject parentGO = (GameObject) gameObject.transform.parent.gameObject;
    To be able to disable the car completely, I had to disable the grandparent - is this an appropriate way to do it? Or is there a better way?
    Code (csharp):
    1. GameObject parentGO = (GameObject) gameObject.transform.parent.parent.gameObject;
    2- The rockets rotate around with the car when the player turns. This is because when the rockets are instantiated, they spawn as a child object of the car they were fired from and then I'm using Physics.IgnoreCollision so the rocket doesn't destroy that car, but consequently this means the rockets will rotate around the center of the car when the car rotates.

    I haven't fixed this yet, any suggestions on what to do?
     
    Last edited: Jul 14, 2015
  9. Haagndaaz

    Haagndaaz

    Joined:
    Feb 20, 2013
    Posts:
    232
    Yea, but you may have to do each step separtely, so a couple get parent lines, or alternatively you could just assign a refference to the proper parent in the inspector
     
  10. Carwashh

    Carwashh

    Joined:
    Jul 28, 2012
    Posts:
    746
    I've been away for a while, so haven't been working on S23R, started developing it again recently. The updates aren't very visual per se, so no screenshots/ video this time.

    I now have a basic flow through the game. Menu -> Cup select -> race 1 -> results -> race 2 (grid positions based on previous race finishing positions) -> results. I was stuck with this for quite a while, as I was unsure of how to:
    - give and store scores
    - add to the running total of scores
    - use the finishing order from the previous race to set the starting positions on the next race (finish first -> start last OR finish last -> start first)

    I'm now using scriptable objects to achieve this, which was new to me. I'll do a better write up of this in another post.

    Today though, I fixed a bug I was having where if 1 AI car got had wheels off the ground, so wouldn't move any more... ALL the AI cars would stop moving.
    It was a silly mistake, I was using
    Code (csharp):
    1.  
    2.     public static bool groundedL;
    3.     public static bool groundedR;
    Static variables used by all cars, d'oh. Now this has been changed, I haven't observed this behaviour again.

    I've also started looking into how to do the camera movement, following the car around but with the player car being closest to the edge it's moving away from. Currently no idea how to do this ... if anyone has any suggestions/ tutorials, I'd be most appreciative!
     
  11. Dennis_eA

    Dennis_eA

    Joined:
    Jan 17, 2011
    Posts:
    375
    If you only need driving up/down slight slopes (not deep ..hills) you can do this by just using the road-colliders normals at this point.

    Also, when doing this you could switch from 3d physics to box 2D, faster :)
     
  12. Carwashh

    Carwashh

    Joined:
    Jul 28, 2012
    Posts:
    746
    I'm not quite sure what you mean @Dennis_eA , I'm also not sure I've made it clear what I'm trying to do. Hopefully this crudely drawn picture will demonstrate it better.
    camera.png

    So, we have X at the center of the screen (pretend that it is...). I'd like to have the camera move slightly ahead of the car, no matter which direction it's heading, so the player can see ahead of them.

    1 is heading downwards, so becomes closer to the camera along the top of the screen.
    3 is heading upwards, so does the opposite of 1, and gets closer to the bottom of the screen.
    Same for 2 and 4, they're close to the edge they're heading away from.

    Not got a clue how to achieve this atm.
     
  13. Dennis_eA

    Dennis_eA

    Joined:
    Jan 17, 2011
    Posts:
    375
    I assume you use rigid bodies (3d) and your car in - in my example - is the transform object.

    Create a GameObject called "CamTarget" - this will be the (main)cameras parent. I assume you want a simple top down camera - so the (local) position of the main camera* would be something like x0 y50 z0 Rot: x90 y0 z0
    (* inside / parented to CamTarget)

    Now, CamTarget.position = transform.position would tie the camera fixed (but floating above it) to the car (the transform in this case)

    2.:
    if (rigidbody.velocity.magnitude > 0.05) {
    CamTarget.position = transform.position + rigidbody.velocity.normalized * 2.0;
    }
    would make the Camera look ahead in the players direction 2 meters / units.

    3.
    if (rigidbody.velocity.magnitude > 0.05) {
    CamTarget.position = Vector3.Lerp(CamTarget.position, transform.position + rigidbody.velocity.normalized * 2.0, Time.deltaTime * lerpSpeed)
    }

    for smooth movement

    4.: you could easily alter this to make it look ahead more / or less based on the speed. This would make a nice effect together with a slight change in the cameras FOV. if you need help with this, just ask :)

    all this is pseudo code, and I use unity script - but: not tested :D
    place all camera stuff inside LateUpdate();
     
    Last edited: Nov 18, 2015
  14. Dennis_eA

    Dennis_eA

    Joined:
    Jan 17, 2011
    Posts:
    375
    get the newly instantiated transform or game object (the rocket) -> SomeRocket.
    SomeRocket.parent = null;
     
  15. Carwashh

    Carwashh

    Joined:
    Jul 28, 2012
    Posts:
    746
    D'oh, so obvious!
     
  16. Dennis_eA

    Dennis_eA

    Joined:
    Jan 17, 2011
    Posts:
    375
    I do not guarantee that ..parent = null; is the fastest or most elegant way. dunno why, but hey I am not a pro or something.
    but you should get rid of instantiating and use a pooling work flow any way :rolleyes:=)

    did the camera stuff work for you?
     
  17. Carwashh

    Carwashh

    Joined:
    Jul 28, 2012
    Posts:
    746
    Working on it now, trying to figure out how to ignore the y axis and make it smooth.
     
  18. Dennis_eA

    Dennis_eA

    Joined:
    Jan 17, 2011
    Posts:
    375
    I don't understand where in your code you want to lock the y axis, but be aware that in most cases often it's absolutely okay to work with Vector3s and re-center one axis, one line later in the code. This is something simple, I wasn't aware of in the first years of scripting (doh) ;)

    Example:
    Code (JavaScript):
    1.  
    2. somePositionOrAngle = SuperCoolVector
    3. somePositionOrAngle.y = 0.0;
    And because you Will run into one particular issue concerning angles, when coding camera-movement stuff if you are not aware of the existence: When lerping angles use Mathf./Vector3.LerpAngle ;)

    I am working on a topdown racer myself atm, so just ask if you need help.
     
  19. Carwashh

    Carwashh

    Joined:
    Jul 28, 2012
    Posts:
    746


    Yeah, I'm aware of being able to change an axis of a Vector 3, I was having a slow day and trying to work out when to set it. Anyway, with the help of some other game devs (I was at a game dev dev day) and your help, I've got it working. Vid above to see it in action, and below is how I did it.

    I had to use FixedUpdate, not LateUpdate, because the gameobject being followed (the player car) is moved in FixedUpdate. Having the car move via FixedUpdate and the camera move via LateUpdate caused a lot of jerky movement - I'm assuming/ guessing the two were out of sync with each other.

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class CameraFollow : MonoBehaviour
    6. {
    7.     private GameObject player;
    8.     private Rigidbody playerRigid;
    9.     private Transform playerTransform;
    10.     private Vector3 playerPos;
    11.  
    12.     public float lerpSpeed = 0.1f;
    13.  
    14.     public float followDist = 5.0f; // how close to the edge of the camera the player will be
    15.  
    16.     private Vector3 normVelocity;
    17.  
    18.     void Start ()
    19.     {
    20.         player = GameObject.FindGameObjectWithTag("Player");
    21.         playerRigid = player.GetComponent<Rigidbody> ();
    22.         playerTransform = player.transform;
    23.         transform.position = playerTransform.position;
    24.     }
    25.  
    26.     void FixedUpdate ()
    27.     {
    28.         float tweenPercent = 1f;
    29.         float maxStartPercent = 10f;
    30.         if (playerRigid.velocity.magnitude < maxStartPercent)
    31.         {
    32.             tweenPercent = playerRigid.velocity.magnitude /  maxStartPercent;
    33.         }
    34.             normVelocity = playerRigid.velocity.normalized;
    35.  
    36.         playerPos = new Vector3 (playerTransform.position.x + normVelocity.x * followDist * tweenPercent,
    37.                                    playerTransform.position.y,
    38.                                 playerTransform.position.z + normVelocity.z * followDist * tweenPercent);
    39.  
    40.             transform.position = Vector3.Lerp (transform.position, playerPos, lerpSpeed);
    41.  
    42.     }
    43. }
     
  20. Dennis_eA

    Dennis_eA

    Joined:
    Jan 17, 2011
    Posts:
    375
    Great.

    Please, test the following:

    1. In the rigidbodies inspector set interpolation to Interpolate AND put your camera stuff back into LateUpdate (this is were it belongs..)

    2. Modify the (Edit-> Time) Time Manager to 0.1666667 (for 60fps), max Step 0.1 Scale 1

    (1.) alone should help and solve the jittering. If not, there is some problem which should NOT be solved by placing camera stuff inside Fixed Update IMO.
     
  21. Carwashh

    Carwashh

    Joined:
    Jul 28, 2012
    Posts:
    746
  22. Carwashh

    Carwashh

    Joined:
    Jul 28, 2012
    Posts:
    746
    So I've added a few things since my last update!
    - Camera effects
    - Improved camera follow
    - Support for controllers (only tested with the Steam Controller so far)
    - New main menu
    - Cup select screen
    - Cups
    - Score boards (for individual races and cup progression)
    - Started work on weapons, destroying cars and respawning
    - Added scenery items to the first track, so it looks better and the camera doesn't see outside into nothing

    I'm liking the direction the main menu and character select screens are going in, I'm just not sure what to do with the backgrounds.

    Main Menu:
    Screen Shot 2016-01-07 at 12.49.37.png

    Character Select mock up:
    Screen Shot 2016-01-06 at 17.48.11.png

    Track images:
    Screen Shot 2016-01-07 at 12.49.43.png Screen Shot 2016-01-07 at 12.49.51.png Screen Shot 2016-01-07 at 12.50.04.png
     
  23. Carwashh

    Carwashh

    Joined:
    Jul 28, 2012
    Posts:
    746
    Time to resurrect this thread!

    It has been a long time since I've been able to work on S23R, had other things on the go, now back "full" time on it and have done quite a bit over the past 2 or 3 months..

    - Fixed car shadows, so there are no longer gaps
    - Added all character scriptable objects
    - Added all car scriptable objects
    - Update cars with varying speeds and bonuses
    - Added character select screen
    - Edited ring track, kept it simple but made it less boring
    - Created temp prefab for items needed to launch a race without going to the main menu
    - Started creating car list prefab, so the spawn order can be manipulated
    - Added character select
    - Added car select, which now also gives the player the correct car in game
    - Updated all car prefabs with weapon slots
    - Updated car prefabs with names and ids
    - Updated spawn controller to use list of car prefabs, cars are no longer required in the scene
    - explosions added for rockets
    - explosions added for cars
    - Improved player respawning, by adding a path of nodes. Player will now spawn on the last waypoint they passed.
    - Added PlayerPath (for spawning, and future weapons) to both tracks
    - Improved the look of water
    - AI cars now fire backwards too
    - Stopped rockets being able to go through some meshes
    - updated to Unity 5.5
    - other stuff

    I've now got a build with a full player loop, getting close to a full vertical slice of features. This video shows the state of the current build (up until the explosions on the list above)


    Whilst trying to tweak the spawning of enemy cars, I moved some code thinking it would do something else, but it ended up stopping the updating of waypoints and provided me with this cool looking bug:
     
  24. Carwashh

    Carwashh

    Joined:
    Jul 28, 2012
    Posts:
    746
    I've recently restarted this project and using HDRP, just getting the new project up to the same feature level as the original proejct.

     
    jamespaterson likes this.
  25. Carwashh

    Carwashh

    Joined:
    Jul 28, 2012
    Posts:
    746
    I've been spending a lot of time working on the AI, getting them to make it round the track without overshooting a corner and not get stuck.

    After tweaking all the settings (so each car has unique speed/acceleration/turning/etc) I started off with a 'brake volume' - basically a trigger cube, once a car hit the cube it would brake and slow down. This worked ok at first, but as each car has different settings the brake volume could accommodate all of them at one size, so I binned this off and tried a different way.

    There are waypoints around the track, the AI has a target waypoint to move towards, when it gets close enough the target waypoint changes. I added a speed restriction to the waypoints, an event is fired when the target waypoint changes and this value is grabbed, a quick calculation is done (defaultMaxSpeed / waypoint.SpeedPenalty) and the car will adjust its speed accordingly. With some tweaking of waypoint positions and adding a couple more.. I've got something I'm really happy with.

     
  26. diwang

    diwang

    Joined:
    Sep 14, 2015
    Posts:
    30
    Interesting , the gameplay is quite HD in my opinion but there's too much quality difference between character/car selection menu and the race itself , you should focus more on improving the menu graphic so it looks better . And also you should add temporary invincibility when the game start so people don't just shoot each other right after game started.