Search Unity

3D Side-Scrolling Shmup: How to pull this off?

Discussion in 'Game Design' started by cyangamer, Oct 11, 2017.

  1. cyangamer

    cyangamer

    Joined:
    Feb 17, 2010
    Posts:
    234
    Hi all,

    I'm working on a mobile side-scrolling game and development has been going well so far, but there's one obstacle that I'm stuck on.

    In 2D shmups, you probably have bullets that "pass over" background objects while hitting foreground objects -- no need to worry about issues like perspective or Y distance here. This means your player can shoot at planes or turrets/buildings with ease.

    With 3D, we have the Y distance and perspective to deal with. Turrets and buildings are on the ground, planes are in the air, and the player's bullets have to be able to hit them both. Bear in mind that the player will be continuously shooting automatically like in a lot of other mobile shmups.

    Super-tall colliders haven't the most precise.
    Orthographic camera distorts the background and actually makes it blend more with the foreground.

    It's a really interesting problem, especially considering that I know for a fact that it's doable.

    Does anyone have a take on this? How do the professionals do it?
     
  2. jchester07

    jchester07

    Joined:
    Jun 28, 2016
    Posts:
    24
    I'm also interested to know how they do it.
    If I do it, I'll create a tall collider for the bullets. but as you've said it's not the most precise and it really is on perspective camera projection.
    I tried using two cameras overlaying each other through layers. one with orthographic and the other one with perspective. Still no good and having multiple cam maybe inefficient.
     
  3. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    I don't understand the problem. 3D colliders work just fine. Are you asking a game design question, or an implementation question?
     
  4. jchester07

    jchester07

    Joined:
    Jun 28, 2016
    Posts:
    24
    As I understand the problem is not with the collider but on how it looks on gameplay.
    The car is on the ground and the plane is on the air (height 10). The red capsule is the bullet (height 5).
    The problem is on perspective projection. The bullet should almost hit the plane but you see it as if its still far away. If I set the bullet height equal to the plane, then the bullet appears to be on top of the car or pass over it depending on where it is now in the camera view.

    Orthographic
    orthographic.png
    Perspective
    perspective.png
     
    cyangamer likes this.
  5. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    The only difference I see in those screen shots is that, with perspective projection, the car and plane shadow look slightly smaller. I don't see a problem with the bullet in either case (except that it's not casting a shadow, which makes it very ambiguous). If its Y=5, it should go between the car and the airplane and not hit either one. If its Y=10 (i.e. same as the plane), it should hit the plane.
     
  6. theANMATOR2b

    theANMATOR2b

    Joined:
    Jul 12, 2014
    Posts:
    7,790
    Can you show an example of this?

    Does layer order help with this 'problem'?

    Example provided looks like 2.5D to me, not true 3D. The shadow of the plane does not deform while going over uneven surfaces, it looks like it stays flat, so the example is faked 3D, not a true 3D shmup, maybe using layers? :)
     
  7. cyangamer

    cyangamer

    Joined:
    Feb 17, 2010
    Posts:
    234
    Thanks for the feedback. jchester07, yes this is basically the problem I'm trying to solve.

    The challenge here is that I don't want the bullet to miss the car or an enemy plane. If something is on the same Z axis as the player, the player should be able to shoot at it and know that it will hit whether it's a turret on the ground or a plane in the sky. Planes are easy and in those cases a regular collider will do. It's the stuff on the ground that's challenge. When the camera is angled in a 3D perspective scene, you'll run into the issue where the bullet is in a different spot There are plenty of solutions (for example, regular 3D colliders, like you said, would work if I wanted enemies (both planes and turrets) to shoot them directly at a player instead of along the Z axis. However, I have experimented with this and it looks weird).

    Sure thing.
    orthographic_3Dshmup.JPG perspective_3Dshmup.JPG
    The image on the left just looks like some abstract painting and is a little disorienting. moving back the camera makes it look even more like painted textures on a flat plane. And then you have the one of the right lets you clearly see topography.

    Granted, this isn't a real issue. I could (and will if need be) make orthographic projection look a little better with some lighting and better texturing (I need to do that anyway), but now that I know it's possible to have a 3D perspective background I want to try and figure it out.

    It probably could.

    It's a clever mix to be sure, and yes I think there's 2D-style physics at play. But the models are definitely in perspective (even the little tanks). As the example shows, we have big planes that can roll back and forth, large buildings are in 3D perspective but can also be shot at, but bullets that seem to go straight, and shadows that are so soft it's hard to tell if they're deforming or not.

    One thing I noticed when watching the example clip in 1/4 speed: when the tanks fire their purple bullets, they're tiny at first but then they quickly grow in size and they keep that size (while pulsating) until they hit the player or leave the screen. That makes me think that turrets are shooting 3D bullets at their Y value (with a 2D-looking shader), and they're increasing the bullets' altitude until they reach the player's altitude, and then they keep going.

    That may be the secret. I'm going to try this and see what happens.

    That won't explain how the player can shoot the tanks though. That might just be regular tall colliders like JoeStrout said. You don't have to be as precise with those and in fact they should be a little generous -- as long as the player feels like it's fair.
     
    JoeStrout and theANMATOR2b like this.
  8. jchester07

    jchester07

    Joined:
    Jun 28, 2016
    Posts:
    24
    Ahh yes. I removed the shadow of the bullet as it doesn't look right hitting both ground and air units regardless of its Y position as long as they are in the same Z position.
    They must be using a parallax effect if so and still using perspective view.
     
    theANMATOR2b likes this.
  9. Sluggy

    Sluggy

    Joined:
    Nov 27, 2012
    Posts:
    985
    I've done something similar to this in a top-down shooter. It's fairly simply as long as you know the ground rules. It was achieved by attaching a 'tall' 3D collider to entities and then aligning them face the camera directly. It gave the perfect illusion of a 2D, screens-space hitbox. However, I ended up abandoning it because the player could jump and with the tall colliders it was impossible to actually jump over projectiles.
     
    InfiniteStates likes this.
  10. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    21,155
    Just because the visuals are three-dimensional doesn't mean the gameplay has to be as well. There are a good number of games out there, including the very video you linked, where the third dimension is completely ignored. Unity's colliders do not need to match the object you attach them to. Nothing prevents you from using 2D colliders with 3D objects.

    Alternatively you can just scale the collider for every object along one axis by the maximum height of the world.
     
    Last edited: Oct 15, 2017
    Kiwasi, Sanhueza and wccrawford like this.
  11. cyangamer

    cyangamer

    Joined:
    Feb 17, 2010
    Posts:
    234
    Nice. That's actually a pretty creative solution. Too bad it didn't work out. I came up with something a little different.

    Scaling the colliders caused some issues with precision when I tried it. Either objects would not be hit by bullets or they would be hit without actually being touched by bullets. It's probably possible to jerry-rig it, but I came up with something a little different -- more like what you mentioned first. :)

    What I did was lower the player so that it, enemy planes, and turrets are all at nearly the same altitude. Then I put the player, planes, and turrets on another layer (rendered by a different camera) so that they would always appear on top. Visually this works perfectly, and the player wasn't that high up to begin with so the terrain still looks okay. This is probably not the solution used in the example, but they also have the staff to implement something more elegant (like having 3D world with perspective with 2D physics colliders).
     
  12. felipeorion_unity

    felipeorion_unity

    Joined:
    May 16, 2018
    Posts:
    1
    I'm facing the same problem. Anyone got a good solution?
     
  13. olaHalo

    olaHalo

    Joined:
    Feb 12, 2015
    Posts:
    32
    I'd just increase the size of the collider so they are on the same plane even if the objects are not on the same plane.
     
    theANMATOR2b likes this.
  14. hexagonius

    hexagonius

    Joined:
    Mar 26, 2013
    Posts:
    98
    I would also go for the 3D world with 2D colliders solution. The only alternative I can think of is writing a little collision system yourself, where every 3D entity is transformed into camera space and given a boundingbox. Maybe transforming the boundingbox corners into camera space and make them into a rectangle. In that space, which is basically 2D, you can do simple overlap tests. When it comes to visually correcting the bullets height according to their targets, that's a whole different story. You'd need to forward predict collisions and move the bullet up or down accordingly, in advance.
     
    theANMATOR2b likes this.
  15. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Well there were at least three in the thread you can use.

    I would personally use 2D colliders, scaled to match the apparent size of the 3D object.
     
  16. InfiniteStates

    InfiniteStates

    Joined:
    Sep 30, 2019
    Posts:
    6
    This works perfectly for a top-down Raiden-like schmup (or the example linked in the OP, which is an excellent game BTW, but with way more depth and perspective).

    Thanks Sluggy, you're a life saver!
     
  17. jamespaterson

    jamespaterson

    Joined:
    Jun 19, 2018
    Posts:
    399
    I faced this same issue with my shemup which is "2d in a 3d environment". For the most part i did not create very tall colliders. Instead my solution was to define a canonical "game plane" in which most of the action occurs. Ground or distant targets that need to collide have their colliders projected onto this plane on every update. Not super accurate but good enough. Good luck with your projects!
     
  18. newjerseyrunner

    newjerseyrunner

    Joined:
    Jul 20, 2017
    Posts:
    966
    My game is a top-down shoot em up in a fully 3D world. I have a number of helpful features to facilitate easier shooting in 3D space from a fixed perspective.

    First off, I have a crosshair that can be controlled with the mouse/controller. This allows the player to tell the game what they actually want to shoot at. The cursor exists in 3D space, and jumps up and down in the world depending on the height of what it's on. This cursor movement also causes subtle movement of the camera, which allows the parallax to be much more obvious that it otherwise would be.

    I also have some weapons not fire in exactly straight lines. My rocket launcher for example, from above looks like it's firing rockets straight at a target, however if you look at it from the side, the rockets actually start off moving up, then flatten out, then dive to their target. This allows it to fly over obstacles that might be in the way.

     
    jamespaterson likes this.