- Home /
Hotline miami style shooting controls from an angled top-down perspective?
I've hit a dead end and could use some help from those more experienced than me.
I'm making a top down 2D adventure/shooter game in a sci-fi setting. The graphic perspective is comparable to 2D Zelda games or Stardew Valley. However, for combat, the mechanic I'm trying to achieve is that you hold down a key (left shift in this case) and the cursor switches to a crosshair and you are able to rotate and shoot your gun Hotline Miami style. The obvious issue with this is that as HLM is actual top-down perspective, it's a relatively simple task to just have the character sprite rotate to the mouse position, but due to the Zelda-like perspective of my setting and character, this isn't an option.
My approach to making a solution to this while still maintaining the feel of how hotline miami's aiming/shooting works was to use math to create an imaginary X in the screen with the player being in the center where depending on which of the 4 sides of the X the mouse was in while the player was in combat mode, the sprite would change to facing that direction. Then I figured I would separate out the arms/gun from the sprite and put them as separate child objects of the player and edit the animations themselves to change to the correct sprite for each direction being faced. I figured I could then create a separate script specifically for the arm/gun child object that would make it rotate to face the cursor while the body of the sprite was limited to only the 4 cardinal directions through the X method mentioned above. In theory, I figured this could give the same smooth feeling of the HLM aiming system while still maintaining an angled perspective and limiting the main body of the sprite to only be facing 4 directions like how it is in Zelda.
I spent a good 6 hours refining this and positioning the child arm/gun objects perfectly so that they were in the perfect position for each frame of the simple character walking animation. I got to the point where it finally looked right and seamless and the arm/gun sprite would correctly change to the correct sprite and layer order in the animation depending on which direction the body was facing.
Where I'm getting stuck on is now trying to get the arm object to rotate to the crosshair cursor. It doesn't seem to be working out in the way I want. Since all the different facing arm sprites have different "up" or "forward" directions for their vector3s, using traditional rotating scripts to change the direction of the sprite facing towards the mouse cursor (similar to what would be used for a top down 2d space shooter) doesn't seem to work. I'm starting to dread that I've gone way far down a path that won't work for what I'm trying to accomplish.
Does anyone have any ideas on how to accomplish what I am trying to do with this game mechanic? I'm still kind of a novice when it comes to scripting in unity, so in all of your collective, more experienced opinions, am I going about this in the right way or is there an obviously better way to accomplish this that I am missing? I feel like I have dumped a ton of time and resources into getting this to work and I'm frustrated and discouraged that I've gotten this far and seem to have hit a dead end. Any ideas are helpful.
Your answer
Follow this Question
Related Questions
How can I rotate an object towards a collision normal in 2D? 0 Answers
How to flip 2d character walk movement? 3 Answers
Problem with 2D gun rotation script (Would really apreaciate help) 1 Answer
Face target first then move forward to it - Top Down 2D 1 Answer
How to keep Diagonal Movement Direction in 2D Isometric game? 0 Answers