x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Is there a way to work out whether a character is idle?

Hi all,

I'm new to Unreal Engine and I've been trying to work this out and Google all over the internet but I can't seem to find an answer. I'm trying to make it so when my character is idle, he will slowly lose stamina. I've created a stamina bar that works and everything, but I'm not to sure how to check whether my character is idle or not, with the blueprints? And if so, then decrease the stamina in the stamina meter. Is there a way to do this?

Thank you in advance!

Forgot to add this but I'm adding this now, I'm creating a simple 2D side scrolling game with Unreal's 2D side scrolling mode

Product Version: UE 4.18
Tags:
more ▼

asked May 03 '18 at 06:06 PM in Blueprint Scripting

avatar image

MikeFParkin
1 1 3

avatar image Velrin May 03 '18 at 06:08 PM

What would you define as idle? No movement or rotation after a period of time? No input events after a period of time?

avatar image MikeFParkin May 03 '18 at 06:14 PM

I realised I didn't mention that I'm making a 2D side scrolling game, in the question. I just updated it as I obviously don't care about the z axes.

I would define idle idle as no movement at all (No jumping, no moving left or right). Other input by pressing random keys or moving the mouse shouldn't be able to override this affect and stop the player from losing stamina.

Have any ideas?

(comments are locked)
10|2000 characters needed characters left

2 answers: sort voted first

I would recommend creating a float within your SideScrollerCharacter. On tick add the delta value to the new parameter. If it goes above a certain threshold you can start the damage.

When movement/jump input is triggered you can reset the float to 0.

more ▼

answered May 03 '18 at 06:18 PM

avatar image

Velrin
370 2 7 12

avatar image Velrin May 03 '18 at 06:21 PM

alt text

idletime.png (329.0 kB)
avatar image MikeFParkin May 03 '18 at 06:37 PM

I just tried that but whenever I run it and stand still, I can see in my blueprints that the character is always moving, even when I'm idle so therefore I can never execute the stamina decrease?

avatar image Velrin May 03 '18 at 06:45 PM

alt text

input.png (104.2 kB)
avatar image Velrin May 03 '18 at 06:46 PM

That should do the trick. I didn't realize that InputAxis MoveRight ticked every frame when the axis was 0.

avatar image MikeFParkin May 03 '18 at 07:07 PM

alt text

avatar image MikeFParkin May 03 '18 at 07:07 PM

So I'm sorry for being such a newbie, but what am I doing wrong?

avatar image Velrin May 03 '18 at 07:11 PM

You want to set idle time to 0.0 if the second branch of your input function is true. Right now you're setting idle time to 0 if the axis 0.

avatar image Velrin May 03 '18 at 07:13 PM

alt text

avatar image MikeFParkin May 03 '18 at 07:26 PM

I tried that but whenever not moving, it doesn't set idle time to 0?

avatar image MikeFParkin May 03 '18 at 07:27 PM

alt text

avatar image Velrin May 03 '18 at 07:30 PM

You don't want to set the idle time to zero if you're not moving. The idea is to tally up time in your tick function, only resetting the variable if we detect input. If the axis value is 0, then we don't want to reset the idle time.

avatar image Velrin May 03 '18 at 07:31 PM

You're also going to want to set the idle time to zero if the first branch is true.

avatar image MikeFParkin May 03 '18 at 07:59 PM

Okay so I set the idle time to zero for the first branch but how do I make the idle time float tally up?

avatar image Velrin May 03 '18 at 08:07 PM

Set up your "Event Tick" similar to how I did in the image further up this thread. Don't do a custom event.

avatar image MikeFParkin May 03 '18 at 08:09 PM

I tried that but since there's already an "Event Tick" used for animations I can't add a new one?

avatar image MikeFParkin May 03 '18 at 08:17 PM

I deleted the animation "Event Tick" and created a new matching yours and it still doesn't work? I feel like I'm missing something really simple...

avatar image MikeFParkin May 03 '18 at 08:18 PM

alt text

avatar image Velrin May 03 '18 at 10:42 PM

I have a little time to spare if you want to send me your project. I'll take a look and see whats missing.

(comments are locked)
10|2000 characters needed characters left

On Tick, get actor velocity --> Get Vector Length --> Float = 0. That will return whether the character is idle. Hope that helps :)

more ▼

answered May 04 '18 at 01:08 PM

avatar image

Kit Kat134
198 1 8 8

(comments are locked)
10|2000 characters needed characters left
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question