Welcome to Netrider ... Connecting Riders!

Interested in talking motorbikes with a terrific community of riders?
Signup (it's quick and free) to join the discussions and access the full suite of tools and information that Netrider has to offer.

Flash MC game development: need some phsyics help

Discussion in 'The Pub' started by jekyll, Apr 21, 2008.

  1. Transplanted from:

    Hi all,

    I'm writing a flash motorcycle game (for shits and giggles, though I intend to find a commercial use for it once it's presentable). The key aim, other than being fun, is to provide as realistic a simulation of motorcycle handling as is possible in a graphically limited, 2d top-down flash game.

    To this end, I need some advice on the physics of motorcycle handling. I am a programmer - not a physicist, mathematician, or person particularly knowledgeable about the theory of bike handling.

    I need a fairly complete set of formulae which are *as simple as possible* - yet still realistically describe the handling dynamics of a motorcycle.

    Can anyone provide any book recommendations / links / specific advice?

    thanks in advance amigos,

    - J[/url]
  2. Thanks jd, the wikipedia article is exactly what I needed to start out.

    I've seen that book online before - I'll take a closer look and maybe order it.

  3. FWIW, current control scheme for comment

       TAB   q  w  e  r  t
       CAPS   a  s  d  f  g
       SHIFT   z  x  c
    mouse_x       : look left / right 
    mouse_y       : throttle
    s             : push left handlebar
    f             : push right handlebar
    SHIFT + S     : push left handlebar HARD
    SHIFT + F     : push right handlebar HARD
    w             : head check left
    r             : head check right
    e             : shift up
    d             : shift down
    SPACE         : clutch
    middle_click  : clutch
    mouse_wheel   : shift up / down
    a             : lean body weight left
    g             : lean body weight right
    click mouse   : front brake
    SHIFT + click : front brake HARD
    CAPS          : toggle rear brake
    TAB           : apply rear brake progressively / toggle off / arrest wheelie
    1-6           : block shift to nth gear
    `             : select neutral
    m             : toggle auto / manual transmission
    q             : move body weight backward
    t             : move body weight forward
  4. So approaching a corner would go something like:
    Mouse Y, Mouse Click+Tab+Q+Space+Mouse Y+D+Space, S+A :shock:

    That's worse than entering cheat codes on a Playstation.

    Noticed in the other thread someone mention TT on the PS2 - you might also want to check out Riding Spirits 2. Graphics and gameplay were kinda sucky but it did have a fairly intuitive advanced mode that used one stick of the PS2 controller for the bike, and the other for shifting the weight of the rider. Physics seemed reasonably realistic, more so than TT since highsides and powerslides were quite possible.
    Given that USB controllers mimicing those of the PS2 or Xbox are fairly common you might want to consider making allowances for people to use those instead of the keyboard+mouse. Given they're analog that would eliminate the need for separate commands for hard braking or turning.
  5. Too bad if i want to go around a hard left corner with a light bit of front brakes... and yes, it does happen ;)
  6. You're dead right - it'll be a big challenge to make it appropriately complex AND usable / fun. I'm still thinking about it.

    What I *want* to achieve is that basic control of the bike is quite easy, but getting maximum performance is quite challenging.

    To try to put it in context, here's an example of what a well-practised player, approaching a tight left hand corner at truly illegal speeds might do:

    1) Set speed & select gear:
    begin rolling off mouse_y (throttle)
    hold mouse_click (front brake) & tap CAPS (toggle rear brake to on)
    ... 1 second passes
    hold SHIFT (braking at maximum capacity)
    ... 1 second passes
    middle_click + scroll_wheel_down (push-scroll w/ middle finger)
    ... 1 second passes
    release SHIFT (ease up on front brakes - only if braking HARD)
    ... 1 second passes
    release mouse_click (get off brakes)*

    * When the rear brake is toggled on, releasing mouse_click should also release the rear brake.

    2) Look (mouse_x) - moving your head helps initiate turn-in and also ensure any traffic hazards are visible
    3) Shift body weight to the inside (a)
    3) Push right bar (f or SHIFT-F) to tip the bike over
    ... 1 second passes
    4) Get on the gas (mouse_y) early in the turn
    ... 2 seconds pass
    5) Push left bar and look through the exit (s or SHIFT-S, mouse_x) to bring the bike upright as the exit approaches.
    ... 1 second passes - bike is now upright
    6) Shift up (middle_click + mouse_wheel_up, mouse_y) as required
    7) Tuck in (t) for the straight :D

    Compared to a new player starting (as is the default) on a far less powerful scooter, with no gears to worry about, approaching the same turn at a far lower speed:

    1) Set corner entry speed:
    Roll off throttle and apply brake, which is optional depending on entry speed (mouse_y + mouse_click)
    ... 2-3 seconds pass
    2) Look through corner (mouse_x) to initiate turn.
    Looking far enough through the corner will cause enough handlebar input as a side-effect to get around the turn, as long as the entry speed is quite low.
    3) Move head (mouse_x) to keep chin pointed at corner exit; this lets the bike stand up by itself (at low enough speeds). Throttle (mouse_y) is kept constant
    ... for 2-3 seconds
    4) Roll on throttle (mouse_y) once turn is complete

    This is what I'd like to achieve, anyway: a high level of potential complexity and challenge, with a low barrier to entry and readily discoverable optional controls (ie, well thought out control layout and in-game help). I'd like it to be as challenging, or as relaxed, as the player wants it to be- just like riding a real bike.

    I have no idea if I'm being too ambitious at this stage - a lot of it depends on my success, or lack thereof, with the physics model, as well as making good usability & gameplay decisions. In any case, I'll be pretty comfortable with Actionscript 3.0 by the time I've got a working beta, which is one of my primary motivations.

    I'll check out Riding Spirits 2 for sure - once I track down a PS2 ... and, I don't think Flash is able to use a USB console-style controller, but I'll look into it. In any case, it would only ever be an optional alternate input device - the game has to work with mouse + keys, lack of analogue controls be damned.

    EDIT: Actually holding a modifer key (eg ALT / CTRL) to temporarily repurpose the mouse x/y axes for something else is an idea I've been playing with, but I couldn't think of anything which you would never want to do at the same time as look or alter throttle. Moving rider body weight might fit the bill though ... ???

    I value your feedback on the controls - I still think some of the keybindings / etc will need to change, but did I manage to make them sound viable in general terms?

    Thanks for your input.
  7. Yeah, I do it often enough. Why would that be a problem with the proposed controls though?

    mouse click = front brakes

    AFAICT that doesn't conflict with any other controls, except the way it interacts with SHIFT, which is an important point.

    SHIFT + S or F is "hard countersteer". SHIFT + click is "hard front brakes". This is how I propose to deal with any ambiguity about which has priority.

    Say you're approaching a right hander at speed, trail-braking aggressively. You're holding CLICK+SHIFT, applying hard front brakes, and it comes time to lean the bike over. You reach for S ...

    RULE #1 : when SHIFT + mouse_click are depressed, pressing S or F applies *normal* (not HARD) pressure to the bars. Rationale: you're obviously trying to trail-brake aggressively, and want to smoothly transition from braking to cornering load on the front tyre, not snap it over suddenly.
    Having initiated the turn with S, you release SHIFT but hold mouse_click(now just moderate front braking) but you now want to turn in faster to avoid a patch of gravel. Your pinky gropes for SHIFT and your balls retract in anticipation ...

    RULE #2 : when mouse_click AND "s" or "f" are depressed, pressing SHIFT increases the pressure on the bars, NOT on the front brakes. Rationale: If you wanted to brake really hard in the middle of a turn (!?), you wouldn't be pressing the bars at the same time.
    Sound reasonable? If so, thanks for bringing it up - if not, thanks for bringing it up, and can you please explain why?
  8. Only problem I see is having controls like steering, weight and body movement as purely on/off digital inputs. Would kind of spoil the "feel" of the game if smooth cornering involves having to vary the rate at which you tap the keys instead of making minor adjustments to an analog input.

    I think the one thing you need to consider is whether you're trying to make a "game" or a "simulation". Most of the fun in a game lies in the fact that it allows people to escape from reality, and do things they couldn't possibly do in real life.
    A simulation on the other hand would be a great tool for improving real life riding but not if the controls are completely different to real life. And there's nothing really natural about having no ability to make minor adjustments to steering and brake input (how can people practice stoppies otherwise ;)).
  9. Absolutely. It's *the* defining problem.

    I thought of doing things like the faster you tap a button the more braking you get, etc, but my quick prototypes told me it's a bad idea.

    It's all about which compromises to make - what inputs deserve the scarce and coveted analogue controls, and what compromises / hacks can make the others work reasonably well?

    I think tweaking the sensitivity of steering to the rider's head position (mouse_x) at different lean angles would make minor mid-course steering adjustments with the mouse quite viable. The "feel" of how the bike turns could easily make or break the game, so I expect to spend substantial time tuning how the mouse_x and handlebar / lean controls interact with the steering and each other.

    I envisaged tapping SHIFT or TAB to modulate stoppies / wheelies respectively; both keys would have a "soft" attack / decay, not a hard ON / OFF effect.

    And - I want it to be a game which is also a simulation :)

    # 1 - Fun
    # 2 - Realism
    # 3 - Fun

    Unless I can find someone to pay for it, in which case they get to rewrite the list however they like.

    Thanks for the help.
  10. That's fair enough. Just think you need to be careful not to produce something that's too overwhelming either to people who've never ridden a bike but would like to (which this game could be perfect for), or to experienced riders who aren't that proficient with computers.
    I'm not sure there'd be that many people willing to persist with learning a complex set of controls. It does work for some flight simulators but when it comes to bikes I suspect the target market might be a lot smaller.
  11. I agree with what you're saying. It will be a big challenge to get right.

    I've been playing Assassin's Creed on PC, which rocks in many ways. Every time you complete an assassination you (re)gain a new weapon / combat ability (grab, counterattack, dodge attack, etc), and you're funnelled through a trainer who explains the controls for your new skill and lets you practice that skill in isolation on a dummy target. You can return at any time to brush up.

    Something similar might work well for this game. When you start, you're told how to use the mouse to control the throttle, front brake & steering, and you're on an automatic scooter. The other controls are all optional and could be introduced one at a time when it makes sense - eg next step is a postie bike w/ centrifugal clutch, so you shift but don't need to worry about a clutch. Then you get a CB250 with a manual transmission and the clutch is introduced. Etc ...

    Also, I've been thinking about the point you raised about analogue controls. I think the mouse x-axis could be used with modifier keys to good effect to make steering entirely analogue.

    Something roughly like:

    (no modifier) : mouse x-axis controls player view angle helmet rotation, which provides some steering input and determines what can be seen.

    ALT : mouse x-axis controls handlebar input only - helmet / view angle is "locked" in place

    ALT + SHIFT : mouse x-axis controls both view angle AND steering input together

    Rider body position I don't see as needing fine-grained control; tap tap tap or whatever for drop shoulder -> slide bum across -> hang off race style would do fine.

    The front brake is the other dimension of control I'd really like to have as analogue. Since you're generally rolling off the throttle as you squeeze the lever, and vice versa, a similar approach of using a modifier key to alter what the y-axis controls might work well - or even have them linked and both controlled by the y-axis simultaneously.

    Thinking about mimicking the real world controls, you reach forward and squeeze to roll off the throttle and grab the brake - so mouse forward and click to brake (with the y-axis modulating lever pressure once the button is depressed), mouse back to accelerate might be a good approach.

    Along similar lines, the clutch should probably be operated not by the thumb (SPACE) or right middle finger (mouse wheel button) but by the first two fingers of the left hand. If the left hand is free from having to control steering inputs this should be more tenable.

    Would anyone intentionally want to apply the front brake & throttle at once (apart from some MotoGP superstars who, I've heard, use it to shorten the wheelbase during cornering)?
  12. What, no burnouts? :LOL: (almost needs to be a separate game just for stunters).

    Good idea about the progressive learning model, although I still think you'd need to have an option to let people set any bike to "easy" mode (ie auto shift, auto body lean etc.) just for those that are naturally impatient or just want to play the game (and may come back to the more advanced stuff later).
    Using flight sims as an example perhaps have a menu screen that allows people to choose their own level of realism - with the cash/points awarded in game suitably adjusted to suit the level of difficulty.
  13. Hmm ... *strokes chin* ...

    Yeah, I figured I'd have 'm' toggle any (geared) bike between auto / automatic clutch / manual shifting. There would have to be an option to get a standard (eg 250cc) bike straight away if you wanted to skip the scooter, but I was also thinking of a persistent (server-side) user account & garage for ongoing acquisition of bigger, badder vehicles.

    Hanging off and other advanced controls I'd considered optional but constantly available; if utilised correctly they'll improve your cornering speed etc and provide their own reward in terms of pursuing the game objectives (eg, you can deliver more packages as a courier or whatever).
  14. While you're at it, throw some supermoto action into it. It'll take a touch typist to finish that level.
  15. Cool idea, but i don't know anything at all about dirt bikes / motards or how to ride them.

    Can you think of anywhere that explains the basics, like what that foot out thing is all about and why they all lean the wrong way?