Forum rules - please read before posting.

A timer that appears in a menu via a trigger

Hi, I have a continuous trigger that opens a menu, which is just some text and a timer. I want the timer to go down over time the longer the player stays in the trigger. How would I link the timer up so it goes down while I am in the trigger?

Comments

  • Ummm... be careful with the Continuous option in triggers, you should be aware that OnTriggerStay is a lot more expensive than Enter and Exit. Specially doing GetComponents calls inside an OnTriggerStay is really, really expensive (which is what AC must be doing if you select the option: Any Object with Component).

    Anyway, I'd recommend using one trigger object with two trigger scripts instead (one set to Enter and one set to Exit). When the player enters the trigger you run a countdown actionlist and when the player gets out, you kill that actionlist.

    Then, the countdown actionlist could be like this: 
    1. Variable:Set set to -1 (will decrement by 1).
    2. hook previous to an Engine:Wait 1 second.
    3. hook the engine:wait to a Variable:Check and check if timer is 0.
    4a. if not 0 hook back to the variable set.
    4b. If timer is 0, you can do whatever you have to do if the timer has ended.

    This way you create a loop that gets you get a continuous countdown, until the player leaves the trigger (cause the Exit trigger script will kill the actionlist) or the timer reaches 0. You can reset the timer variable before you start the countdown actionlist to ensure the countdown will always start from the same number.
  • edited May 2017
    Thanks very much man that is awesome, I will try that!.. Appreciated. Works a treat, is there any easy way to represent the time on screen? Like reuse that quick time event progress bar thing? I noticed there is no decrement on my AC only increment, but counting up works too.
  • Any variable can be displayed in a menu label by using variable tokens, e.g. by inserting "[var:1]" as the label's text - see Section 10.4 of the Manual.

    A variable's associated token can be found in it's entry in the Variables Manager.
  • Great, that's nifty and works well. But is there a way to use the "progress bar" (like for QTEs) in a menu?
  • edited May 2017
    You could try using a slider. In the slider settings set Slider Affects to Float variable (this allows you to link the slider to a global variable). You'll want to turn the variable into a float (or make sure your ationlist copies the value of the timer into a new float global variable) Because we are using integer values you won't have a smooth transition but you will still get a bar/meter you can display.  Ah, don't forget to untick User Can Change Value (or the player will be able to drag the slider).
  • Thanks dude, I will try that, once again much appreciated.
  • Sorry to bump this thread - 
    I tried something similar - making a timer by using onEnter and onExit triggers instead of Continuous .
    The counter starts, but doesn't stop.

    When using Continuous  my timer messes up - what's the appropriate to do a timer with the Continuous trigger so it starts when a rigidbody enters the trigger and stops when the object exits?
    I basically want to have the player stay on a trigger for a specific amount of time.

    Any direction would be much appreciated.

  • Continuous is called every physics update, IIRC, so you wouldn't be able to use that unless you were using some custom Actions that account for the time-difference each frame.

    OnEnter/OnExit should be the way to go, so working out why the timer doesn't stop should be the priority here.

    Are none of the OnExit actions not running?  An ActionList: Comment Action can be used to print messages to the Console to help you learn that.

    Any ActionList that is running on a loop when the player is in the Trigger will need to be set to Run In Background, otherwise it may prevent the OnExit Trigger from starting.
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.