Forum rules - please read before posting.

More AC + UFPS problems (solved)

edited October 2014 in Technical Q&A
Hey there,

After Chris solved my AC+UFPS camera jitter issue, I was able to work on a prototype for my game with the two assets. However, I stumbled on a few more issues. None of them are so dramatic as the camera jitter I had before, but I still want to adress them:

Issues with a NPC, dying and pathfinding:
  1. I made a cube (NPC) that follows a path and after talking to the cube and selecting the dialogue option "follow me", the cube follows the player (using Character: NPC follow). If the player dies and respawns (using UFPS logic), the cube moves to the player respawn spot. However, sometimes the cube doesn’t do this, but just decides to go to a place far-off the map if the player dies.

  2. I added a boolean variable called followingPlayer (bug occurs with both global and local variables) and set it to false. It will be set to true once the player talks to the cube and selects the dialogue option "follow me". When choosing for the other dialogue option "bye", it stops the dialogue and checks the value of the variable followingPlayer. When set to false, the cube should move along his path (which works), but when the variable is set to true, the cube should skip this step in the action list and thus keep on following the player. It doensn't however, and always returns to his path, whether he was following the player before or not.

  3. The cube walks on his path by default. However, the path sometimes ignores the first node of the path and creates its own.

  4. The player can talk to the cube and then get shot and die (using UFPS
    logic). When this happens, the dialogue options from talking to the cube remain on screen, even
    after the player respawns on a different location. Is there a way to abandon a conversation when the player's health reaches zero?

Issues when creating a cutscene

I've set up my UPFS scene and using this tutorial, I want to add a cutscene on start, where we look through a different camera and move the player to a point before the game starts. I get the following problems:
  1. 'Camera: Switch' doesn't seem to work. Can't I use multiple cameras when using UFPS as the movement method?

  2. 'Engine: Pause game' doens't affect UFPS movement. The player can still move around even when the rest of the scene is paused. Is there a way to stop the player from moving during a cutscene with this movement method?

  3. 'Character: Move along path' or 'Character: Move to point' with 'Is Player' set to true doesn't make the player move at all. It does create a path in my scene for the player to walk in, but I need to move the player manually to the end point in order to "finish" the cutscene. If I move around freely when the path is created, the movement is constrained and the camera jitters. Unity clearly tries to keep the player on the path, but the whole point is that it doesn't move by itself.

Comments

  • edited September 2014
    A lot of little things here.  I'd like to deal with the main issues before tackling the finer ones.

    Issues with a NPC, dying and pathfinding

    It sounds like you want to have an "On death" ActionList asset that runs when the UFPS Player dies.  This asset would take care of anything on the AC side of things, e.g. re-calling the follow Action, ending the conversation etc.

    This would be a custom script job.  It's surely possible to trigger a custom script upon death, and you just want to call:

    AdvGame.RunActionListAsset (theAssetName);

    to trigger the asset.  You may want this asset to trigger a "local" Cutscene within the scene, so that you can have different Cutscenes run depending on which scene the player is currently in (use the Engine: Check scene Action).

    Issues when creating a cutscene

    I haven't had issues with manually moving the Player prefab myself - does your Vp_FPController Inspector have a Freeze state?  Having that should sort these issues out.

    You can also use the Engine: Manage systems Action to temporarily switch to e.g. Point And Click mode.  If UFPS mode doesn't natively let you switch camera, simply switch to P&C mode at the beginning of the Cutscene, and switch back at the end of it.
  • Issues with a NPC, dying and pathfinding:

    That sure sounds like a solution for the main issue, but I'm not sure how to trigger a custom script upon death. I tried to make a simple C# script as well as to edit one of the UFPS base scripts to get this done, but without getting it to work. I'm not really a programmer myself, so I kinda need some help here. How do I trigger a custom script upon UFPS death exactly?

    Issues when creating a cutscene

    My player already has a freeze state, but still I'm not able to move it via 'Character: Move along path' or 'Character: Move to point' in an ActionList.

    When the movement method is set to UFPS, I cannot switch cams. Switching it temporarily to P&C during a cutscene works to look through a different camera, but when switching back to the UFPS movement method I cannot control my player anymore. It seems that I lose all forms of control if I change the movement method back and forth during a cutscene. :(
  • Issues with a NPC, dying and pathfinding:

    I was just assuming this was a common feature in UFPS.  I couldn't say for how it would be done, but it's likely that someone's done this before.  Better to get in touch with the creator of the asset, in this case.

    Issues when creating a cutscene

    If the implementation works as it should, you shouldn't need to switch movement method.  This prefab works fine for me - try it and see how it goes for you.
  • edited September 2014
    Issues with a NPC, dying and pathfinding:

    I've posted a question about custom scripts to the UFPS forums. As soon as I know how to run the custom script, I'll let you know if it works.

    Issues when creating a cutscene

    Same thing happens, even when using your prefab as a player. No camera switch and the player is not moving on the path.

    This is what my ActionList looks like:

    image

    (Both Engine:Manage Systems nodes are disabled for now)

    And this is what happens:

    image

    The player spawns at PlayerStart and just stands there, where the camera also goes. So no camera switch and no automatic player movement. I can walk him to the other side of his path to "start the game" and "end the cutscene" manually, but there is no way of him going there by himself. If I move outside the path, my movement is restricted and the camera tries to focus on the path, resulting in jitter. This is done with your prefab, but the same happens with my player prefab.
  • edited September 2014
    So I got a custom script from someone at the UFPS forums who helped me out.

    using UnityEngine;
    using System.Collections;

    public class tt_DoStuffBeforeDying : MonoBehaviour
    {

    private vp_FPPlayerEventHandler a_Player = null;

    void Awake ()
    {
    a_Player =this.transform.root.GetComponentInChildren();
    }


    protected virtual void OnEnable()
    {

    if (a_Player != null)
    a_Player.Register(this);

    }


    protected virtual void OnDisable()
    {

    if (a_Player != null)
    a_Player.Unregister(this);

    }


    void OnStart_Dead()
    {
    Debug.Log("starting DEAD");
    // add your code here .....
    }

    }


    I put the script on my Player and it seems to work, since I see the "starting DEAD" text in the console.
    I then replaced "// add your code here ....." with the code you mentioned to run my ActionList "uponPlayerDeath":



    AdvGame.RunActionListAsset (uponPlayerDeath);



    However, I get the following error: Assets/Area_52d/Scripts/tt_DoStuffBeforeDying.cs(37,17): error CS0103: The name `AdvGame' does not exist in the current context.
  • Ah, sorry.  You need to write "AC.AdvGame instead - just a namespace issue.

    As for the Cutscene problem, make sure that Pause until finish? is checked in the Character: Move to point Action.  That may or may not be the end of it, but that'll certainly need to be corrected first.
  • edited September 2014
    Issues with a NPC, dying and pathfinding:


    I tried the namespace change in the script already. Doesn't work. It gives me three errors:



    Assets/Area_52d/Scripts/tt_DoStuffBeforeDying.cs(37,48): error CS0103: The name `uponPlayerDeath' does not exist in the current context



    Assets/Area_52d/Scripts/tt_DoStuffBeforeDying.cs(37,28): error CS1502: The best overloaded method match for `AC.AdvGame.RunActionListAsset(AC.ActionListAsset)' has some invalid arguments



    Assets/Area_52d/Scripts/tt_DoStuffBeforeDying.cs(37,28): error CS1503: Argument `#1' cannot convert `object' expression to type `AC.ActionListAsset'




    Issues when creating a cutscene


    Good point on the Pause Until Finish, but unfortunately it doens't change a thing. I still need to move the player myself...
  • Issues with a NPC, dying and pathfinding:
    It sounds like an issue with your declaration - the namespace issue is solved now.  Have you declared the uponPlayerDeath variable as a public ActionListAsset and defined it in the Inspector?

    Issues when creating a cutscene
    I'm sure this "Freeze" state is key to all this.  You're sure the Freeze script is attached to it, not just the name is defined?  As a further test, try using the Player: Constrain Action to lock movement completely - that should prevent movement regardless of whether or not you're in a Cutscene.
  • Issues with a NPC, dying and pathfinding:
    Awesome, that was it! I'm such a newbie in scripting, I hope I can think of these things myself one day :P
    Anyway, now it runs my unponPlayerDeath ActionListAsset once I die, which stops the grey cube from following me and turns off the conversations, as can be seen in the screenshot below.

    image

    I was wondering if there is an easier way to stop all conversations and dialogues on screen by the way. The screenshots only shows three objects to affect, but in reality, a lot more conversations could be happening when dying. Should I include them all manually in the ActionList or is there a way to stop all the currently running dialogues/conversations?

    With that out of the way, my problems 1 and 4 from the opening post are solved. Any ideas on problem #3 though?


    Issues when creating a cutscene
    Yep, I included the Freeze state the way it should be included. When using Player: Constrain I indeed lock my walking movement but I can still move the cursor/look around. All other problems remain: the camera snaps back facing it's marker that it should move to everytime, the character doens't move to the marker and no camera is being switched.

    I'm getting the feeling that I'm not really making progress here. Is there a way that we can set up a Skype meeting so I can show you what's happening on my screen?
  • A simple custom Action could easily end the active conversation - all you need to do is unset the playerInput script's activeConversation variable.  I may include this in 1.39, as it may be useful to others as well.

    You'll have to be more clear about what you mean by your problem in 3 - screenshots of the intended / actual paths involved would help immensely.

    A Skype wouldn't be as helpful as seeing the project for myself - PM me a UnityPackage file of your assets.  Please be mindful to include only the assets needed to recreate the problem, though.
  • edited September 2014
    Issues with a NPC, dying and pathfinding:

    I don't really know how to unset that variable from within my custom action's script. As mentioned before, I'm not really a scripting genius, so I'm looking forward to your implementation in 1.39.

    As for the path problem, here you see the path selected:
    image

    After starting the game, the path is altered, as you can see in the screenshot below. The first node remains in it's place, but that's not where the actual path starts from. The NPC that follows the path is selected below (the placeholder grey cube in this case).

    image

    Problem 2 in my OP is solved btw. I set up the ActionList in an incorrect way.

    Issues when creating a cutscene
    I will PM you the UnityPackage later today, thnx :)
  • After thinking about it, I'm not convinced to include such an Action in the official AC release, since it's use is only for rare instances such as this.  However, since it was simple to write I've uploaded it for you to download here.

    Regarding the Path, it looks like the Path GameObject is somehow being teleported - node "0" is it's position, and moving it won't affect the other nodes.  At what point does it change position - when the NPC starts moving, or when the game starts?  Are there any other actions that may be causing it to move?
  • edited October 2014
    Thanks for the script. It works well and stops the active conversation. Unfortunately, my problem seems to be a bit more complex, since I also want the game to stop other on-screen text (speech) as well as soon as the player dies. This could be speech within Interactions or in Dialogue Options. Of course your script only stops active Dialogues, not active Interactions or Dialogue Options. Is there a way to do this, so I can stop all current on-screen text as soon as the player dies? (I tried just using Dialogue: Stop speech, but that just stops the current Play Speech action within an ActionList, but further Dialogue within the actionlist will still be triggered, so that's not it unfortunately).

    As for the path, it's changed as soon as I start the game. The NPC gets teleported to the original node 0 position, but then follows the path that got adjusted when starting the game. Weird. I solved the problem by making a new path with the copied Paths component from the original one. There were no external factors that could move the path's first node as far as I'm aware of, so let's just hope this bug doens't return. If it does, I'll let you know.

    PS: I didn't have the time to create the UnityPackage yet, but you'll get that ASAP. The cutscene problem is currently the toughest one I'm facing.
  • edited October 2014

    There's a function in the ActionListManager script that'll kill all currently-running ActionLists.  You can modify the script (by inserting this code into the Run function) to call it:

    GameObject.FindWithTag (Tags.gameEngine).GetComponent ().KillAllLists ();

  • Awesome, that's it!

    Also, when I was making the Unity package to send you concerning the cutscene, I stumbled on the solution. It was so simple that I wanted to hit myself on the head: I forgot to set the Cutscene properties to "Pause gameplay". I had it set to "Run in background", that's why I couldn't switch camera or make the player move to a marker. D'oh! Oh well, I'm really glad I figured that one out. Now I can finally make cutscenes in my first person adventure :)

    With that said, all the problems I was facing in the OP are solved now. A small recap of the solutions:

    Issues with a NPC, dying and pathfinding:
    1. Solved by using a custom script when player dies that triggers an ActionListAsset with NPC:Follow set to "stop following".
    2. Solved by setting up the ActionList in the right way.
    3. Solved-ish by deleting the nodes and creating a new path. Weird that it happened though.
    4. Solved by using a custom script when player dies that triggers an ActionListAsset. This ActionList triggers Pause game for 3s, followed by Stop Speech and a custom action that kills all Dialogue and then all currently running ActionLists.

    Issues when creating a cutscene

    All issues here solved by setting the cutscene to "Pause gameplay".


    Case closed. Thanks for all your help, Chris!

  • Great!  Look forward to seeing your work.
  • For anyone looking for an updated version for an Action List On Death for UFPS / UCC 2:

    using UnityEngine;
    using Opsive.Shared.Events;
    using AC;
    
    public class ActionOnDeath : MonoBehaviour
    {
        public ActionListAsset uponPlayerDeath;
    
        public void Awake()
        {
            // Register for the event when the component starts. The event registers with the local GameObject (the first parameter) so 
            // the component must be added to the same GameObject as the object that is sending the "OnDeath" event.
            EventHandler.RegisterEvent<Vector3, Vector3, GameObject>(gameObject, "OnDeath", OnDeath);
        }
    
        /// <summary>
        /// Receives the "OnDeath" event.
        /// </summary>
        private void OnDeath(Vector3 position, Vector3 force, GameObject attacker)
        {
            Debug.Log("The object died");
    
            AC.AdvGame.RunActionListAsset(uponPlayerDeath);
        }
    
        public void OnDestroy()
        {
            // Unregister from the event when the component is no longer interested in it. In this example the component is interested for the lifetime of 
            // the component (Awake -> OnDestroy). 
            EventHandler.UnregisterEvent<Vector3, Vector3, GameObject>(gameObject, "OnDeath", OnDeath);
        }
    }
    
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.