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)?

Advertisements

2 thoughts on “Oh, it seems I got distracted.”

  1. See if there’s a function to get the resolution of the screen. (There almost certainly is). Then you can use that variable as your limit.
    width = Screen.getWidth();
    if (x>-width/2 && x<width/2) { …

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s