Adventure Creator Wikia
Advertisement

This script causes a first-person player camera to face the "grab point" of the current Draggable / PickUp object being held at all times. To use it, set the Movement method to First Person, and attach the script below as a component on a GameObject in the scene.

FirstPersonFaceDrag.cs

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

public class FirstPersonFaceDrag : MonoBehaviour
{

private DragBase faceObject;


private void OnEnable ()
{
EventManager.OnGrabMoveable += OnGrabMoveable;
EventManager.OnDropMoveable += OnDropMoveable;
}


private void OnDisable ()
{
EventManager.OnGrabMoveable -= OnGrabMoveable;
EventManager.OnDropMoveable -= OnDropMoveable;
}


private void Update ()
{
if (faceObject != null)
{
Vector3 bodyDirection = faceObject.GetGrabPosition () - KickStarter.player.transform.position;
KickStarter.player.SetLookDirection (bodyDirection, true);

KickStarter.player.SetTilt (faceObject.GetGrabPosition (), true);
}
}


private void OnGrabMoveable (DragBase moveable)
{
faceObject = moveable;
}


private void OnDropMoveable (DragBase moveable)
{
faceObject = null;
}

}
Advertisement