Do any of the 2D games use controllers?

,

Just finished up the Brick Breaker game (got a post in the show-off board) and I was thinking it would be great to add in controller support (like XBox controller). So I was wondering if any of the future games in the class - Gallaga clone, PvZ clone, or Metroidvania clone - introduce game controller inputs.

Cheers,
Eric

I can’t remember specifically but adding controller input should be really easy. When using the axis inputs they should
by default map. I would have to revisit block breaker but it may just work

Unity supports certain controllers by default. You could test that with Input.GetAxis("Horizontal");.

should it work in the Unity “Game” window? or only on compiled games?

Haven’t been able to make it work, but maybe I’m doing something naive here?

Here’s a branch I created with my attempts to make it work with an XBox One controller (this is on Windows 10 where I use the controller successfully in commercial games): https://github.com/djotaku/BlockDestroyer/tree/controllersupport

Just for the purposes of getting things going, I’ve only tried to move the paddle left-to-right with the controller. So I changed line 43 in Paddle.cs ( https://github.com/djotaku/BlockDestroyer/blob/controllersupport/Assets/Scripts/Paddle.cs ) In other words, I haven’t tried to configure a button to fire the ball yet.

I’ve also changed the input settings in Unity to try and make things work.

Any help would be great!

Thanks,

Jump to lecture “Movement & Time.deltaTime” (currently #88) to learn how to move an object via code. This is the script of that lecture.

Oh, OK so you guys do cover controllers. I’m only a couple lectures away from that lecture so I’ll see when I get there (in case the instructor has other caveats to note) and if it works I’ll come back and mark your reply as the solution. Does this forum also have the ability to change the original post title to name it “solved”? (Or does clicking solution take care of that for me?)

We do use Unity’s built-in functionality but we do not explicitely cover controllers.


See also:

Frustratingly, I can’t figure out what I’m doing wrong. I downloaded the project here:

The code is at: https://www.youtube.com/redirect?q=https%3A%2F%2Fdrive.google.com%2Fopen%3Fid%3D1R-HarCLcnsF4bXCiM3jm9oANxFRq4vPD&event=video_description&v=mwrfV-2lpg8&redir_token=XOV068RhMECKbyWEiupdngqXAbV8MTU3MTg2NTAyMkAxNTcxNzc4NjIy

When I run his code, the controller works. But when I try and do something similar in the
Laser Defender code, it doesn’t work.

Laser Defender: https://github.com/djotaku/laserdefender

At this point I think it’s got to be something really dumb or subtle because I’ve checked all the settings and the code seems to line up.

I’m afraid I cannot help you with problems that are beyond the scope of this course. I use an XBox 360 controller. It works by default.

Maybe this tutorial helps:

If not, Please feel free to ask our helpful community of students for advice in our official Discord chat.

You could also test Unity’s new input system.

Hey Nina,

Thanks for checking w/ your Xbox 360 controller. I’m not sure if there’s an order to turning on the controller first or maybe related to the fact that I had to reboot my computer for something else, but it works now. But, thanks for also pointing me to the new input system. Looks like it’s going to be a lot more useful.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms