Friday, 4 March 2016

Updated Code

___________________________________________________________________________________________________

Updated Code to fix camera:

using UnityEngine;
using System.Collections;
using System;

[RequireComponent(typeof(Camera))]
public class CameraMovement : MonoBehaviour {

    public float _width = 200.0f; //width and height of camera movement
    public float _height = 200.0f;

    public float _movementDamping = 1.0f; //this reduces movement

    private Vector3 _currentVelocity;
    private Camera _camera;

    private void Start()
    {
        _camera = GetComponent<Camera>();
        _currentVelocity = new Vector3(0.0f, 0.0f, 0.0f);
    }
    private void Update() // this update stops the camera from flying off into space
    {
        float aspectRatio = (float)Screen.width / (float)Screen.height;

        Vector3 targetPosition = new Vector3(
            (Input.GetAxis("Mouse X"))*100.0f,
            (Input.GetAxis("Mouse Y"))*100.0f,
            transform.position.z);

        if (targetPosition.x > _width / 2)
            targetPosition.x = _width / 2;
        if (targetPosition.x < -_width / 2)
            targetPosition.x = -_width / 2;
        if (targetPosition.y > _height / 2)
            targetPosition.y = _height / 2;
        if (targetPosition.y < -_height / 2)
            targetPosition.y = -_height / 2;

        transform.position = Vector3.SmoothDamp(transform.position, targetPosition, ref _currentVelocity, _movementDamping);
    }
}

Thursday, 3 March 2016

Attempt at Scripting #2

___________________________________________________________________________________________________

I tried following another tutorial using a different code as the first one didnt really work out very well.

The code is as follows:
(and is attached to my main camera)

using UnityEngine;
using System.Collections;

public class CameraMovement : MonoBehaviour {

private float speed = 2.0f;
private float zoomSpeed = 2.0f;

public float minX = -360.0f;
public float maxX = 360.0f;

public float minY = -45.0f;
public float maxY = 45.0f;

public float sensX = 100.0f;
public float sensY = 100.0f;

float rotationY = 0.0f;
float rotationX = 0.0f;

void Update () {

float scroll = Input.GetAxis("Mouse ScrollWheel");
transform.Translate(0, scroll * zoomSpeed, scroll * zoomSpeed, Space.World);

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

if (Input.GetMouseButton (0)) {
rotationX += Input.GetAxis ("Mouse X") * sensX * Time.deltaTime;
rotationY += Input.GetAxis ("Mouse Y") * sensY * Time.deltaTime;
rotationY = Mathf.Clamp (rotationY, minY, maxY);
transform.localEulerAngles = new Vector3 (-rotationY, rotationX, 0);
}
}
}

- This code has actually worked out a lot better, it does more or less what I want it to and so may just require a bit of tweaking to get right.

- If possible, i just want the camera to follow the mouse without having to click, because i want the player to be able to click on objects in the room and interact with them as a separate action.

- Also, the camera isn't focusing on the 2D image and keeps moving away from it. This needs to be fixed. I need to see if I can look up a way to do that.

- Also, I want it to follow the mouse not rotate around one point, so as you move the mouse along the image, the camera moves with a sort of parallax effect.

Monday, 22 February 2016

Setting up my project and Parallax Attempt

I spent today setting up my project in Unity. I want to create a parallax effect on my environment and also want some elements in the scene to be interact-able. Because of this, I started out by separating up my sketch into multiple objects. I then imported them and changed their "texture type" to "sprites".





To create the parallax I separated my assets up on the sprite editor. I used the automatic slice to separate them into four different objects. I also set the sprite mode to multiple rather than single as there are multiple sprites on this png.
 This is what the scene looked like built up in different layers on the game view. I changed the camera from perspective to orthographic and changed the "far" clipping from from 1000 to 10 to save memory. This is because with a 2D side-scroller you don't need that much distance between the camera and the layers.





Adding the assets to sorting layers and then locking them allows you to keep the assets in the order you want.







Using the tutorial suggested to me by Karl Inglott I created this code to try and parallax my background.








When the parallaxing script is applied to the background layer, the game does nothing when played in the "game panel".


When it is applied to all the asset layers, the following happens.....









___________________________________________________________________________________________________


Help!
(This problem, I think, initially, is because the parallax is not tied to the mouse movement like I'd like it to be. Also, I'm wondering if there needs to be an area the camera is fixed to so when the parallax moves it doesn't zoom straight off the background layer. This happens if the code is applied to the main camera.)

Friday, 19 February 2016

Environment



This is the latest version of my environment. I like this the most out of the ones I've done. I think it works a lot better with the open space and lots of different objects. It has a lot of potential for interactivity. I'm thinking of adding maybe some more stuff like balls of gold (that have been made from the hay) but I dont want to overcrowd the scene.

I think this also create a "tower" feel without looking too depressing and dreary.

I used Rapunzel's tower from Tangled as inspiration because that is something that, in the fairytale, was quite dark but Disney made it a lot brighter/a happier (looking) place.