Forum rules - please read before posting.

Object Close Up like Gone Home etc!

Hey! So Chris adding a great feature for being able to examine objects up close

https://adventurecreator.org/tutorials/examining-objects-close

Although there were a few things that I wanted specifically from it, so I extended the code a bit.

This is what the end product looks like

So normally in first person, while examining an object using the regular tutorial, when you turn down player influence on the object, it freezes the camera, but you can no longer rotate the object. And if you turn up player influence, You still move around in first person view a bit.

To overcome this you can actually set player influence to 0 but add a line of code to the Return Pick Up code.

KickStarter.player.freeAimLocked = true;

Here is the full code of how I implemented.

I also added some code to turn on animated background and change the layer the object is on! More than happy to explain this more if you need it.

There may be a better/easier way to do this, but this is what I did!

using UnityEngine;

using System.Collections;

using AC;

public class ReturnPickUp : MonoBehaviour

{

public Marker markerWhenHeld;

public float moveSpeed = 10f;

//Attach quad in front of camera to give blurred background 
public GameObject m_Plane;

//Attach object you want to focus on
public GameObject m_mesh;



private Vector3 originalPosition;

private Quaternion originalRotation;

private bool doReturn;

private bool isHeld;

private DragBase dragBase;




private LerpUtils.Vector3Lerp positionLerp = new LerpUtils.Vector3Lerp();

private LerpUtils.QuaternionLerp rotationLerp = new LerpUtils.QuaternionLerp();




private void OnEnable ()

{

    dragBase = (DragBase) GetComponent<DragBase>();






    EventManager.OnGrabMoveable += GrabMoveable;

    EventManager.OnDropMoveable += DropMoveable;

}





private void OnDisable ()

{

    EventManager.OnGrabMoveable -= GrabMoveable;

    EventManager.OnDropMoveable -= DropMoveable;

}





private void Update()

{

    if (doReturn)

    {

        transform.position = positionLerp.Update (transform.position, originalPosition, moveSpeed);

        transform.rotation = rotationLerp.Update (transform.rotation, originalRotation, moveSpeed);

    }

    else if (isHeld && markerWhenHeld != null)

    {

        transform.position = positionLerp.Update (transform.position, markerWhenHeld.transform.position, moveSpeed);

    }

}





private void GrabMoveable (DragBase _dragBase)

{


    if (_dragBase == dragBase)

    {
        foreach (Transform child in transform)
        {
            // Changes objects layers to new layer to allow 'blurring' of background
                child.gameObject.layer = LayerMask.NameToLayer( "Camera2" );
        }

        // Activates plane with background effect
        m_Plane.SetActive(true);

        // turns off the screen lock so you can rotate the object without having any first person influence
        KickStarter.player.freeAimLocked = true;

        originalPosition = transform.position;

        originalRotation = transform.rotation;



        doReturn = false;

        isHeld = true;

    }

}





private void DropMoveable (DragBase _dragBase)

{
    //KickStarter.player.freeAimLocked = false;
    gameObject.layer = LayerMask.NameToLayer( "Default" );

    if (_dragBase == dragBase)

    {
        foreach (Transform child in transform)
        {
                child.gameObject.layer = LayerMask.NameToLayer( "Default" );
        }

        m_Plane.SetActive(false);

        KickStarter.player.freeAimLocked = false;

        doReturn = true;

        isHeld = false;



        if (moveSpeed <= 0f)

        {

            transform.position = originalPosition;

            transform.rotation = originalRotation;

        }

    }

}

}

Comments

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.