Returning control to the Player Camera when the Pixel Crusher's Dialogue Panel is no longer .

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
cristo
Posts: 8
Joined: Fri Jul 03, 2015 4:15 am

Returning control to the Player Camera when the Pixel Crusher's Dialogue Panel is no longer .

Post by cristo »

Hi, I'm trying to rework some of this script so that control is returned to the Player Camera when the Pixel Crusher's Dialogue Panel is no longer active, or enabled, at the end of a conversation, when the tick in the inspector switches off on the Dialogue Panel. When this happens I want control returned to the Player Camera.
I tried putting the following into the code, instead of the part where it says 'once the 5 seconds pass', but it isn't working right.


Code: Select all

    if (DialoguePanel.enabled == false) {
            CloseDistanceBoost = 1;
            transform.eulerAngles.y = CCamera.eulerAngles.y;
            CCamera.localEulerAngles.y = 0;
            EnableControls();
            Once = true;
If anyone can please offer a suggestion that would be awesome!

Code: Select all

//---------------------------------------- We Set variables
enum options {Walk,Teleport};  // ADD THIS SCRIPT TO THE "Player" OBJECT AND SET THE VARIABLES
var TargetPosition : Transform; //Position that the player will be teleported to or walk smoothly to
var TargetToLook : Transform; //The object the player will have to look for 5 seconds
var Distance : float = 15; //The distance the player will have to come close to the object to start
var OnceWithinRange : options; // walk or teleport options
var WalkSpeed : float = 0.5; //Smooth walk speed
var LookSpeed : float = 3; //Smooth look speed
var LookTime : float = 10; //Time the player will look at the object (Starts when he enters the range)
private var Once : boolean;
private var Seconds : float;
private var CloseDistanceBoost : float = 1;
private var CCamera : Transform;
public var DialoguePanel : GameObject;
//---------------------------------------- Start Function
function Start () {
    CCamera = GameObject.Find("Main Camera").transform;
   

} //Find camera
//---------------------------------------- Update Function
function Update () {
    if (Vector3.Distance(transform.position, TargetToLook.position) <= Distance && Seconds <= LookTime) { // If within Range
        Seconds += 1 * Time.deltaTime; //Count Time

        if (OnceWithinRange == options.Teleport) { //If you have set the player to teleport then
            DisableControls(); //Disable his ability to control the player and
            transform.position = TargetPosition.position; //Teleport to position
            CCamera.LookAt(TargetToLook); //Look instantly at the target
        }
        if (OnceWithinRange == options.Walk) { //If you have set the player to walk then
            DisableControls(); //Disable his ability to control the player and
            if (Vector3.Distance(transform.position, TargetPosition.position) < Distance/5 && CloseDistanceBoost <= 3) {
                CloseDistanceBoost += 1 * Time.deltaTime; } //add close distance boost
            transform.position = Vector3 ((Mathf.Lerp(transform.position.x,TargetPosition.position.x,WalkSpeed*CloseDistanceBoost* Time.deltaTime)),(Mathf.Lerp(transform.position.y,TargetPosition.position.y,WalkSpeed*CloseDistanceBoost* Time.deltaTime)),(Mathf.Lerp(transform.position.z,TargetPosition.position.z,WalkSpeed*CloseDistanceBoost* Time.deltaTime))); //Walk to position
            //above line makes player walk
            CCamera.rotation = Quaternion.Slerp(CCamera.rotation, Quaternion.LookRotation(TargetToLook.position - CCamera.position), LookSpeed * Time.deltaTime);
            //above line will make the player look smoothly the object
        }
    }
    //----------------------------------------------------------- Once the 5 seconds pass , return the controlls to the player (you can replace the code inside the if statement if u want
   // if (Seconds >= LookTime && !Once) {
    //    CloseDistanceBoost = 1;
      //  transform.eulerAngles.y = CCamera.eulerAngles.y;
       // CCamera.localEulerAngles.y = 0;
        //EnableControls();
        //Once = true;
    } //-----------------------------------------------------------

    if (Vector3.Distance(transform.position, TargetPosition.position) > Distance/5 && CloseDistanceBoost != 1) {
        CloseDistanceBoost = 1; } //Reset closedistance boost
}
//---------------------------------------- Disable player movement and camera control
function DisableControls () {
    GetComponent("CharacterMotor").enabled = false;
    GetComponent("MouseLook").enabled = false;
    CCamera.GetComponent("MouseLook").enabled = false;
}
//---------------------------------------- Enable player movement and camera contol
function EnableControls () {
    GetComponent("CharacterMotor").enabled = true;
    GetComponent("MouseLook").enabled = true;
    CCamera.GetComponent("MouseLook").enabled = true;
}
User avatar
Tony Li
Posts: 22104
Joined: Thu Jul 18, 2013 1:27 pm

Re: Returning control to the Player Camera when the Pixel Crusher's Dialogue Panel is no longer .

Post by Tony Li »

Hi,

What about using Set Component Enabled On Dialogue Event as described in the How To Set Up The Player section? You can use this to disable your control scripts at the start of conversations and re-enable them at the end.

You can also use the OnConversationStart and OnConversationEnd script messages, similar to this:

Code: Select all

function OnConversationStart(actor : Transform) { // (simplified example)
    DisableControls(); // (etc.)
}

function OnConversationEnd(actor : Transform) { // (simplified example)
    EnableControls(); // (etc.)
}
cristo
Posts: 8
Joined: Fri Jul 03, 2015 4:15 am

Re: Returning control to the Player Camera when the Pixel Crusher's Dialogue Panel is no longer .

Post by cristo »

Thanks for the reply Tony.
User avatar
Tony Li
Posts: 22104
Joined: Thu Jul 18, 2013 1:27 pm

Re: Returning control to the Player Camera when the Pixel Crusher's Dialogue Panel is no longer .

Post by Tony Li »

Happy to help! If those suggestions don't do the trick, let me know so we can come up with something that works best for your needs.
Post Reply