timer interval limit

Ask for help about creating mods and scripts for Grimrock 2 or share your tips, scripts, tools and assets with other modders here. Warning: forum contains spoilers!
Post Reply
Granamir
Posts: 202
Joined: Wed Jan 07, 2015 7:19 pm

timer interval limit

Post by Granamir »

I'm trying to make a will'o wisp, and to make movement smooth i increment it by 0.001, this way they move smoothly but very slowly, so i tryed increase (or better decrease) timer interval but lower than 0.01 nothing change.
Has anyone encountered same thing?
Has anyone any idea to make smooth but fast movements?
minmay
Posts: 2790
Joined: Mon Sep 23, 2013 2:24 am

Re: timer interval limit

Post by minmay »

In Grimrock, timers will not activate more than once per update, and updates will not happen more than once per frame. (Off-level components update only on a fraction of frames). Physics are also variable-timestep. To accomplish smooth movement you should use a timer with a very short interval like 0.001 so it will activate once every frame, and use Time.deltaTime() to advance your physics each frame.
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
User avatar
JohnWordsworth
Posts: 1397
Joined: Fri Sep 14, 2012 4:19 pm
Location: Devon, United Kingdom
Contact:

Re: timer interval limit

Post by JohnWordsworth »

EDIT: First comment removed - Good Spot MinMay - This won't work when the user is holding the right mouse button down to look around!

Note, anything done every frame, or in a high resolution timer, needs to be CPU light for performance reasons!
Last edited by JohnWordsworth on Sun Feb 15, 2015 12:15 am, edited 1 time in total.
My Grimrock Projects Page with links to the Grimrock Model Toolkit, GrimFBX, Atlas Toolkit, QuickBar, NoteBook and the Oriental Weapons Pack.
minmay
Posts: 2790
Joined: Mon Sep 23, 2013 2:24 am

Re: timer interval limit

Post by minmay »

JohnWordsworth wrote:If you know you really want something to advance / evaluate on every single frame, then adding an onDrawGui hook guarantees your method is called each frame.
Actually, it doesn't. onDrawGui is not called if the player is free-looking or (IIRC) viewing the automap. And free-look can be used at almost any time, so this method is not really useful for much at all.

So far attaching a TimerComponent to the party with a short interval has worked perfectly for me. (You attach it to the party because components not on the party's level may not be updated, and the party, surprisingly, will always be on the party's level.) I expect using an onUpdate() hook on a CameraComponent or LightComponent would also work, I can't really decide which of these two methods is uglier.
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
Granamir
Posts: 202
Joined: Wed Jan 07, 2015 7:19 pm

Re: timer interval limit

Post by Granamir »

Thank you guys...
...trying to understand how delta time works but seems with no results.
Can u help me? Ty
User avatar
Zo Kath Ra
Posts: 944
Joined: Sat Apr 21, 2012 9:57 am
Location: Germany

Re: timer interval limit

Post by Zo Kath Ra »

Granamir wrote:I'm trying to make a will'o wisp
As a monster or as decoration? (like the fireflies)
minmay
Posts: 2790
Joined: Mon Sep 23, 2013 2:24 am

Re: timer interval limit

Post by minmay »

Granamir wrote:Thank you guys...
...trying to understand how delta time works but seems with no results.
Can u help me? Ty
Time.deltaTime() returns the amount of game time elapsed since the previous frame.
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
Granamir
Posts: 202
Joined: Wed Jan 07, 2015 7:19 pm

Re: timer interval limit

Post by Granamir »

Zo Kath Ra wrote:
Granamir wrote:I'm trying to make a will'o wisp
As a monster or as decoration? (like the fireflies)
I started to make them as decoration (and 'til now that they are)...but maybe i'll decide to make them as monster too, have to check how much difficult is creating a monster.
Granamir
Posts: 202
Joined: Wed Jan 07, 2015 7:19 pm

Re: timer interval limit

Post by Granamir »

minmay wrote:
Granamir wrote:Thank you guys...
...trying to understand how delta time works but seems with no results.
Can u help me? Ty
Time.deltaTime() returns the amount of game time elapsed since the previous frame.
Thank you.
I'll try to figure out how to use it.
Granamir
Posts: 202
Joined: Wed Jan 07, 2015 7:19 pm

Re: timer interval limit

Post by Granamir »

it's done
u can find it here:
viewtopic.php?f=22&t=9522
Post Reply