Navigation

    Fuze Arena Logo
    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Popular
    • Users
    • Groups
    • Help
    • Discord

    Split screen 3d racing game

    Work In Progress
    3
    9
    620
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • monkeee
      monkeee F last edited by

      Im gonna make a 3d racing game that you can play with your friends like mario kart.

      I've got a demo working with aabb collisions and basic car physics. Heres a preview of me and my brother drifting B)

      I want to add slopes but figuring out the collisions is super hard.
      If anyone has any suggestions, let me know!

      PickleCatStars 1 Reply Last reply Reply Quote 6
      • monkeee
        monkeee F last edited by

        More previews:

        1 Reply Last reply Reply Quote 4
        • vinicity
          vinicity F last edited by

          Amazing stuff! Can't wait!

          1 Reply Last reply Reply Quote 1
          • PickleCatStars
            PickleCatStars F @monkeee last edited by

            @monkeee I did a load of work with getting collisions with slopes, and angles of slopes, for terrains, for my game Squishy. there's a bit of a write-up in the thread https://fuzearena.com/forum/topic/1179/wip-the-legend-of-squishy

            and there's also that secret 3d collision thing that's probably a way easier way to go, to be honest. though it won't give you the angle of the slope. I can't remember what the function is called. It's undocumented because apparently performance isn't great, but for a 2 player racing game, it'd be fine. Hopefully someone else will remember...

            monkeee 1 Reply Last reply Reply Quote 1
            • monkeee
              monkeee F @PickleCatStars last edited by

              An update on what ive done so far
              I've worked on making the drifting feel realistic. I want drifting to be a useful game mechanic. However, I found it could have un indented effects. Like pressing the drift button makes the car go faster, when in reality it should slow the car down and provide better handling.

              Here's how I did the drifting mechanic:

              You steer by controlling the cars angle

              player.angle += turn_amount*c.lx
              

              (turn amount is different when drift button pressed)
              Then I calculate the cars forward vector

              player.forward = {cos(player.angle), 0, sin(player.angle)}
              

              Apply some drag and redirect some of the previous velocity in the new forward direction

              player.vel *= drag
              player.vel += redirect_amount*length(player.vel)*player.forward
              

              (Preferably drag + redirect_amount <= 1ish)
              (drag and redirect_amount is different when drifting)

              U make the car drive by applying a force in the forward direction.

              player.vel += player.forward* c.zr
              

              Idk if this is how it's conventionally done, I've tried find more info online but it's all very confusing.

              1 Reply Last reply Reply Quote 3
              • monkeee
                monkeee F last edited by

                Another preview

                1 Reply Last reply Reply Quote 2
                • monkeee
                  monkeee F last edited by monkeee

                  Another update
                  i fixed the drifting bug, it had to do with the order of how the velocity was redirected. I rewrote the drifting physics so that there are only 2 parameters we change:

                  • The time it takes for the car to accelerate from zero to sixty meters ( or units) per second.
                  • The maximum velocity or terminal velocity of the car.
                  turn_amount = 3
                  /*
                  // Could experiment with adjusting turn amount when drifting but so far its causes the car to oversteer by a lot.
                  if c.drift then
                      turn_amount = 5
                  endif
                  */
                  player.angle += turn_amount*c.lx
                  
                  
                  // enter drag manually or use a function to set it based on the time you want the car to reach 60 meters per second
                  drag_coefficient = calculate_drag(zero_to_sixty, terminal_velocity)
                  // Accelerate car such that it reaches a terminal velocity naturally when drag is taken into account
                  acceleration = drag_coefficient*terminal_velocity 
                  player.vel += player.forward*(c.zr-c.b)*acceleration*dt
                  
                  player.forward = {cos(player.angle), 0, sin(player.angle)}
                  speed = length(player.vel)
                  redirect_ratio = 0.1
                  if c.drift then 
                      // Lower redirect ratio gives the drifting effect where the car skids across the road.
                  
                      redirect_ratio = 0.01
                  endif
                  // Most of the velocity is in the same direction as in the previous frame.
                  player.vel *= (1-redirect_ratio) 
                  // Some of the velocity is redirected to direction the player is facing.
                  player.vel += speed*player.forward*redirect_ratio
                  
                  // We apply some drag afterwards
                  player.vel -= drag_coefficient*player.vel*dt
                  // same as player.vel *= (1-drag_coefficent*dt)
                  
                  ............
                  // update position later
                  player.pos += player.vel*dt
                  

                  heres the force equation for the car if we drive it with some acceleration and take into account friction
                  Force = mass * net_acceleration = mass * drive_acceleration - drag_coefficent * velocity

                  Set the force to zero to find the maximum velocity the car can reach. (with mass = 1, i might try different masses to see how it affects drifting)

                  Doing some more maths you can get the required drag_coefficient and drive_acceleration for given terminal_velocity and zero_to_sixty time.

                  // assumed mass = 1
                  function calculate_drag(zero_to_sixty, terminal_velocity)
                      drag_coefficient = -(1/zero_to_sixty) * ln(1-60/terminal_velocity)
                  return drag_coefficient
                  

                  I've tried doing slope collisions for ramps but my collision code is too long and i cba changing it.

                  burger 🍔

                  1 Reply Last reply Reply Quote 0
                  • monkeee
                    monkeee F last edited by

                    I've also added a tag game mode. Theres a tagger and the other car becomes 'it' if the tagger collides with it. There is a five second cooldown so you cant just immediatly tag back. I've been playing this with my brother and he keeps beating me. It's very hard to win when your the tagger 😪. I might change it so the tagger accelerates more quickly (lower zero to sixty time). Then balance this by making the runner more agile by increasing how much they can dirft (lower redirect_ratio).

                    preview:

                    it'll be like a month before i start working on this again, cus of exams, hopefully i dont drop it

                    1 Reply Last reply Reply Quote 2
                    • vinicity
                      vinicity F last edited by

                      Super cool! Thanks for explaining how you made it, that’s always interesting. I’ve thought about doing another car game too sometime.

                      1 Reply Last reply Reply Quote 1
                      • First post
                        Last post