Join us! Nintendo Enthusiast Forums
dark        
Osc blog header photo
Osc's c-blog
Posts 824Blogs 15Following 0Followers 11


 
 

LONG BLOG

GAME IN PROGRESS

   0

Game In Progress header

Welcome, welcome! It's 2019 and I've finally gotten my boots on the ground: I've started developing my (small) game. I also decided to change the title of this blog/update series/thing. Anyways, last year I was able to pin down what I wanted to create. It's basically Super Monkey Ball, without the monkeys and you have to control 2 balls at once (whoa, hey now). Right now it's in the early stages, but let's see what I have done so far.

I had created two spheres and one simple piece of terrain, if you can even call it that. Nothing crazy, just for initial testing.

Initial testing phase

Then, I needed to get the movement of the spheres. This was easy to do because I had already done a sample project that had us create scripts for the spheres. Reuse of code is always encouraged in all aspects programming - it's how so much progress is made instead of starting from nothing. 

In this case, it's a very simple script. Seriously, it's like 4 lines. But this script allows a person to move using the WASD or the arrow keys. It gets the horizontal and vertical axis and - using a Unity built in function - multiplies it by the speed which determines how much force is applied to the sphere to make it move.

Movement script for sphere

When I tested this, it worked like a charm. So, I figured all I had to do was attach this script to a new sphere and I would be able to control both spheres.

And it did do that, but what happened is that I was controlling both spheres at the same time. It wasn't independent. If I moved left or right using either keys, they both moved simultaneously.

This was my first hiccup. I spent a good hour or so trying to find a way to separate the controls. There was much talk of math logic to tie the axis to negative and positive numbers to get left and right. Or just situations that didn't really apply to what I was looking for.

But what I found was a comment linking over to a random tutorial some dude made talking about how to control two players at once. And of course, it's so simple. Just give the GetAxis function a different input name to take in. In my case, add a '1' to the name. Then just change what keys you use in each input setting.

Movement script for second sphere

Why this works is because Unity has an Input Setting that allows you to set the controls to whatever keys or gamepads you want. The function above will get the name of the axis from the Input settings. In my case, the original Horizontal and Vertical inputs were tied to WASD and the arrow keys. So attaching that one script to both spheres is why even though they're different, their input keys were the same. This resulted in simulatenoues movement.

The second script uses 'Horizonal1' and 'Vertical1' control names. This is enough to differentiate the names and get different input controls for each sphere. Depending on which script the sphere has, that's what it will use for movement input.

Input Manager

After finding this out, I changed the Horizontal1 and Vertical1 inputs (as seen above) to ONLY use WASD keys, while the originals ONLY accept the arrow keys. When I tested this again, BAM! It worked!

So the next step was to make the view splitscreen. And you remember how I said I found my solution on some random dude's tutorial? Yeah, he also had a solution to this on that same exact post. I'd buy that guy a drink, If I ever met him.

Anyway, it was another easy thing to do. There was a script I had to make, but again - a sample project I had worked on had the script for this. See how easy this is! So after attaching the scripts to each camera and designating which sphere to focus on, my splitscreen worked.

Splitscreen and movement

So as a first timer, I'm pretty proud of what I've done so far. It might not seem like much, but progress is progress. Funny thing, as I was testing what I've done, something troubled me. Handling two at once, might be a little too challenging! It's still in the early stages but I might change what I do in terms of gameplay. Only time will tell.

Login to vote this up!

LOOK WHO CAME:


Osc   
LaTerry   40
Agent9   17
Dinosir   14


 
 

  0 COMMENTS

Please login (or) make a quick account (free)
to view and post comments.



 Login with Twitter

 Login with Dtoid

Three day old threads are only visible to verified humans - this helps our small community management team stay on top of spam

Sorry for the extra step!

 

About Oscone of us since 9:37 AM on 11.12.2011

Here to play games and make some jokes.
My twitter: guaranteed to be better than the virtual boy (but not by much) https://twitter.com/oscmolo