Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Question resources for coding different styles of player movement?

Discussion in 'Scripting' started by NatureGuard, May 6, 2024.

  1. NatureGuard

    NatureGuard

    Joined:
    Jul 15, 2023
    Posts:
    3
    looking for a guide to coding different kinds/styles of player movement.

    so I've been trying to make a racing game, and I have tried so many different ways to do the movement, and it just does not seem right, I can tune it all I want, but it just stays wrong.
    I have looked into a bunch of things, notably different YouTube videos, that go into ways of doing the movement, but they tend to not make it to clear how it behaves, "does this even do what I want?" is a common question I have, and trying to find the bit I want across all the videos I've checked is a pain. also most of those videos go into platformer type movement, not racing movement, which is a tad different.
    so now I'm looking for something that goes more into a bunch of different styles of movement that one can go thru and find what they want. an example of what I'm looking for is like the book "Game Programming Patterns" (by Robert Nystrom) it goes into coding patterns, some basics of how to make it, and what you'd want the pattern for. its such a big help, highly recommend, I'm actually using the 'state' and 'component' patterns for my movement now, having a different script for particular things the character can do is nice, makes them easier to work on and manage.

    there's just so many ways to move the character.
    like with force or translation? and do you just keep it as a more constant value (just like multiply it by the input amount) or have an element of acceleration to it? then if there is acceleration, do you bring it quickly up to max, or more slowly? what kind of curve should it have?
    and then there's turning, you could use torque, you could add rotation, you could make a vector from input axes and rotate the player to look towards that, which way will get the effect one wants?
    and like a notable thing is drifting, I often run into a thing where you have velocity going one way, and then turn, and keep going that initial way. so say you were going forward which happened to be north, and then you turn to the right (so facing east now), but you keep moving quite a bit to the north (which is now your left) before you really are just going forward. and like I get why its there, I'm using force, and that's how physics works, but as much as I try to tune it with like drag and such it just doesn't seem right, so I'm getting the feeling something is wrong with the aproach, and not just that it needs tuning.
    and so I really want some kind of resource that goes into the how and why of these things, and shows various options and what they are good/bad at so one can decide which to use. I just get the feeling I'm trying to remake the wheel instead of just building off of an already existing wheel, like it really doesn't seem right to be making the wheel from scratch when that's been done already, just need to find a wheel that fits my needs and modify that, ya know? like I'm all for learning how the wheel works and building it, but geez it feels more like I'm pushing different polygons down a hill and watching as they crash and lurch around.

    so does anyone know of such a resource, something that goes into coding different kinds of movement based on what you're trying to achieve?
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    39,013
    Amen NatureGuard... but I kinda think that's just the way things are.

    I doubt there's one central place that could even hold all combinations.

    Honestly your best bet is to study it yourself, and by "study" I mean begin to develop a feel for what different motion schemes do for you by doing small experiments to reveal the differences in a simple uncomplicated context.

    In the example of cars, you mention drifting... drifting is SO much fun you almost certainly want to make it part of any racing game. But really there's a million ways to do this. Do you detect approaching force / traction limits and just begin to offset? Do you reduce force / traction at the moment of drifting? That's what happens in real life as the tires break loose, but it can be VERY hard to control in a game because with reduced grip from drifting, the car may quickly accelerate out of control laterally.

    I say play with it, but do so in simple 2D contexts, like try to remake something like Super Sprint where you can play with different controls related to your traction and speed and turning inputs.

    https://en.wikipedia.org/wiki/Super_Sprint
     
    Ryiah likes this.
  3. dstears

    dstears

    Joined:
    Sep 6, 2021
    Posts:
    151
    spiney199 likes this.
  4. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    6,437
    Start the other way round: what kind of racing car controls (feel) are you aiming for? Is there a game (or several) that closely resembles the style of controls you want? If so, google that ... "how to make race car controller like xxxxx"

    Also: are you willing to spend $$$ on such a controller? There are plenty on the store. You can even get a free one and disect it.

    You could be into realistic racing, then you'd be dealing with in-depth physics simulation stuff that may even be beyond what Unity's built-in PhysX is capable of providing.

    If it's supposed to be arcade racing you're going to cheat and fake all day long until it feels right.

    For both you won't be looking at Youtube tutorials but the in-depth written guides because they offer far better insights. I used to have several go-to articles for both kind of racing games, but particularly for arcade racing. I can't seem to find them though except for this one from 2003 (yes!).
    Those articles may require looking in depth at google results and searching for various keywords because such articles are pushed down by the SEO optimized "touching the surface" kind of crap that gets published up and down on social media. And also because they were always hidden gems, and now they're about 20 years old (hint: racing algorithms didn't change because physics hasn't changed the past 20 years at least).
     
    Sluggy and NatureGuard like this.