I’m on a break… Unfortunately.

Unfortunately, I’m on a break… A temporary one.
I’m still doing some reading and looking here and there, but that’s really all I can do. I must focus on actual responsibilities.

So for those who miss progress, do enjoy these fine folks. I’ll be back before September.

Extra Credits

Advertisements

The Square, it learned how to run.

Yeah, you know, it doesn’t sound that hard to do, and it really isn’t. But, any good game allows your character to run, jump, and do something other than stand around…. unless, that’s what you want. Anywho, I got it to work with the (left)-shift key.

Also, I learned something new. I need to include the *_Data folder for you guys to be able to test out the *.exe. So, here it is in a .rar file. Just download and extract, and play the little white square on the green background. (Download me here: Rawrrr!)

You’ll notice, the little bastard can go off the screen when he runs. Why is that? It’s because the running speed is too high, so it jumps so many pixels between each frame. The logic fails, as the way I have it written so far is that it can’t move further out once the square reaches the edge. However, it can jump  the full distance if he’s only 1 pixel from the edge.

SO… to do list for the next update:

  • Prevent the little square from ever (regardless of situation) going over the edge.
  • Make enemy (black) squares appear randomly on the screen – and – for now, do nothing.

The Square! It stays on the screen!

No more will my objects fall off the world screen! Good god, I love the internet, it really makes my life easier.

So, what I was missing was the Camera.main.ViewportToWorldPoint function. It can be used to pull the edges of the screen, so that even if I switch my resolution, the borders will stay true for that resolution. So, here it is: A bordered world for my little white square

Code:

var leftBorder = Camera.main.ViewportToWorldPoint(new Vector3(0, 0, 0)).x;

if (Input.GetKey(KeyCode.LeftArrow))
{
if (transform.position.x > leftBorder)
{
transform.position += Vector3.left * speed * Time.deltaTime;
}
}

Now, there is a little problem… If my speed is too high, lets say 20 (its 5 now), it’s possible that my little square can jump 19 pixels off  the screen if the center is only 1 pixel away from the border.

So, next step? Make it so that if it would disappear, force it at the the edge. How to do this? I have a couple ideas. I’ll be back later on that!

Oh, it seems I got distracted.

So, it’s been 3 weeks. My bad.

I did think about all this a little – but you know, life gets in the way. Blame the dog. In any case, if I want to make boundary conditions, it’s pretty easy (I’m not taking about collision physics… yet). I just need to add an “if” statement in front of each transform.position, so that if we’re at a position equal / greater than the limit, we can’t go further in that direction.

Recall:

            if (Input.GetKey(KeyCode.LeftArrow))
            {
                transform.position += Vector3.left * speed * Time.deltaTime;
            }

I can simply modify it to be:

        if (transform.position.x > -12)
        {
            if (Input.GetKey(KeyCode.LeftArrow))
            {
                transform.position += Vector3.left * speed * Time.deltaTime;
            }
        }

But, this is kind crappy; it’s a straight limit. I have no clue how it relates to my resolution. What if that value is outside my screen? I know that the center of the screen is coordinate (0,0). What if I change me screen resolution? What if I want my screen to be Cartesian, with the lower left corner of the game being (0,0)?

Moving Square

My first step!

A box that moves on a green background. I know it’s not really a big step, and it took me way too long, but it got done. Just a simple script that allows unity to grab your arrow inputs and moves the square in two dimensions. I don’t have border conditions or another square, or collisions … or anything, it just works. I know how to make the executable, which was my task for today.

Here’s the link to the box “game.”

Next step? Border conditions!


using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SquareMove : MonoBehaviour {
    public float speed = 1.5f;

    void Update () {
        if (Input.GetKey(KeyCode.LeftArrow))
        {
            transform.position += Vector3.left * speed * Time.deltaTime;
        }
        if (Input.GetKey(KeyCode.RightArrow))
        {
            transform.position += Vector3.right * speed * Time.deltaTime;
        }
        if (Input.GetKey(KeyCode.UpArrow))
        {
            transform.position += Vector3.up * speed * Time.deltaTime;
        }
        if (Input.GetKey(KeyCode.DownArrow))
        {
            transform.position += Vector3.down * speed * Time.deltaTime;
        }
    }
}

I’m finally here!

Hello everyone … *chirp* *chirp*

Welcome to Sorrontis Games! I thought I would give myself a little push. I’ve always been dreaming of making games, and now, look at me, I’m learning to code. C# + unity seems to be a good match for me.

So, why a wordpress? I want to catalogue my progress. Maybe, just maybe, I’ll get something nice done!

So, step one : Watch Unity Tutorials and get it up 😉