Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Time based effect not working properly

Author
Message
brunuu
5
Years of Service
User Offline
Joined: 4th Jun 2018
Location:
Posted: 4th Oct 2022 01:10
I'm creating an effect where the sprite has motion trail, that works, but the problem is that depending on the framerate the behavior changes

this script uses time to keep everything at the same speed regardless of framerate but it still doesn't work correctly, the problem here is not the speed
but how many times does it run

at 60fps


at infinite fps

Effect does not play or is reduced at higher framerates


I created here an example with my trail function to demonstrate

SFSW
21
Years of Service
User Offline
Joined: 9th Oct 2002
Location:
Posted: 4th Oct 2022 03:02 Edited at: 4th Oct 2022 03:41
Hi brunuu,

At a glance, it looks like you left a static gap potential in your timer. You're checking for >0.001, but then just reset to 0 instead of accounting for any differential that may be present whenever your limit is exceeded. This can produce a 'wobble' at different framerates. I would initially recommend changing these lines:



This way, your timer deducts by a fixed 0.001 to only remove the step/tick amount you want to apply, accounting for any leftover value above 0.001. So if you're effect time is say, 0.001225, you subtract 0.001 to leave the next phase of your counter starting at 0.000225. This smooths out the movement regardless of framerate and accounts for potential variation since you will almost never have a scenario with a perfect 0 to 0.001 step.

If that doesn't solve what you're trying to do, then a closer look at your timing mechanism may be needed to determine what other possible issue there may be.
brunuu
5
Years of Service
User Offline
Joined: 4th Jun 2018
Location:
Posted: 4th Oct 2022 03:21
The active variable does not store time, Its only use is just to know if the main sprint exists so when it ceases to exist it no longer creates the effect

SFSW
21
Years of Service
User Offline
Joined: 9th Oct 2002
Location:
Posted: 4th Oct 2022 03:41
Woops, yup, I meant the time element. Corrected in the post above and here:

brunuu
5
Years of Service
User Offline
Joined: 4th Jun 2018
Location:
Posted: 4th Oct 2022 10:01
yeh, that will fix the stutters
but not the problem of the effect being different at different frame rates, and I have no idea why
MadBit
VIP Member
Gold Codemaster
14
Years of Service
User Offline
Joined: 25th Jun 2009
Location: Germany
Posted: 4th Oct 2022 10:56
I think it is because you are reducing the alpha value of your trailing effect by fixed values. you should also reduce this based on time.
Or you calculate the alpha value according to the age of the 'trailing patikel'. (age / max_age)*255.0
Share your knowledge. It\'s a way to achieve immortality. (Tenzin Gyatso)

Donations are always welcome.
brunuu
5
Years of Service
User Offline
Joined: 4th Jun 2018
Location:
Posted: 4th Oct 2022 12:13
I've tried something similar, but the problem still persists.


if I try it without making the sprite transparent, I can see that more sprites are created the higher the framerate


MadBit
VIP Member
Gold Codemaster
14
Years of Service
User Offline
Joined: 25th Jun 2009
Location: Germany
Posted: 4th Oct 2022 13:32 Edited at: 4th Oct 2022 13:33
Replace line 88 with this one and you will get a similar effect.

it doesn't look the same now. that's because multiple sprites are rendered over the same spot using additive blend mode. That's why you have a slower gradient.
Share your knowledge. It\'s a way to achieve immortality. (Tenzin Gyatso)

Donations are always welcome.
Prime
1
Years of Service
User Offline
Joined: 15th Jun 2022
Location:
Posted: 4th Oct 2022 14:52
This is the suggestion I posted on discord, with an additional note. I tried it and it works for me. I also tried with not decreasing the alpha and it works as expected.

Prime
1
Years of Service
User Offline
Joined: 15th Jun 2022
Location:
Posted: 4th Oct 2022 16:30
I tried some different values, and I like this effect the best but it depends on what you're going for. If you set the time threshold too low you won't get a consistent effect when you change the frame rate.

brunuu
5
Years of Service
User Offline
Joined: 4th Jun 2018
Location:
Posted: 4th Oct 2022 17:37
Yeh, I also tried something like this
and in fact increasing the time variable solves the problem
but for certain things I will need it to be lower

because this is really only a problem when it goes below +-0.05 seconds
Prime
1
Years of Service
User Offline
Joined: 15th Jun 2022
Location:
Posted: 4th Oct 2022 17:45
If you need the time variable to be effectively lower, you will need to try a completely different approach because what you're asking for is to create new trail positions between frames.
brunuu
5
Years of Service
User Offline
Joined: 4th Jun 2018
Location:
Posted: 5th Oct 2022 15:46
I tried using particles, which works quite well, but unfortunately it is not possible to control the width and height of the particles individually, only the scale

Prime
1
Years of Service
User Offline
Joined: 15th Jun 2022
Location:
Posted: 5th Oct 2022 20:14
I can think of two options you might try. The first is instead of placing a new trail sprite at the current position of the bullet sprite, interpolate the position between the bullet sprite and the most recent trail sprite based on the current value of time, or you could place the new trail sprite the desired distance from the previous one. You'd have to place the first trail sprite a bit differently, maybe place one at the bullet origin when the bullet is created.

The second way is instead of creating, fading, and then deleting trail sprites you could create them when the bullet is created and move them when the bullet moves.
MadBit
VIP Member
Gold Codemaster
14
Years of Service
User Offline
Joined: 25th Jun 2009
Location: Germany
Posted: 6th Oct 2022 06:35 Edited at: 6th Oct 2022 06:48
I think it would look best with particles. Usually you don't need to distort the particle shape.
The only important thing is that you move the emitter with the bullet and not the particles themselves. (SetParticlesPosition)

Alternatively you can create the traileffect with a sprite with a gradient image. This would simplify the complexity of the code and is also resource friendly.


Here is my example:
this should be similar to what Prime describes in his second way.


Share your knowledge. It\'s a way to achieve immortality. (Tenzin Gyatso)

Donations are always welcome.

Attachments

Login to view attachments
brunuu
5
Years of Service
User Offline
Joined: 4th Jun 2018
Location:
Posted: 6th Oct 2022 11:26
it's a good approach making sprites follow another

the reason i can't do with particles, is because particles can only be square sprites, and I can't make the particles have width different from height
and this effect is to be used on various types of sprites of various shapes, including characters
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 6th Oct 2022 12:18
Quote: "and I can't make the particles have width different from height"

with transparent particles this is achievable, not sure if it would be to resource
hungry.

I did try madbits last method and that worked well this end

PK
brunuu
5
Years of Service
User Offline
Joined: 4th Jun 2018
Location:
Posted: 6th Oct 2022 13:41
I think I have an ideia, but
It's possible o layer sprites in front of particles?
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 7th Oct 2022 17:54
brunuu you could make use of the render commands and use particles

an example of fireworks below

PK
brunuu
5
Years of Service
User Offline
Joined: 4th Jun 2018
Location:
Posted: 7th Oct 2022 18:23 Edited at: 7th Oct 2022 18:35
I gathered several of the ideas suggested here and I had this idea
instead of using time to control, why not measure the distance between each position? because position is independent of framerate, 10 pixels is 10 pixels
so I did it like this, I just put a sprite for the trail at a certain distance from the main sprite



and it works!





fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 8th Oct 2022 05:15
Well done
PK
brunuu
5
Years of Service
User Offline
Joined: 4th Jun 2018
Location:
Posted: 8th Oct 2022 20:47
well it seems nothing works properly at a low frame rate
and found that my sprites ignore collision at low framerate, a bullet for example, ignores collision with an object
also uses time-based movement
brunuu
5
Years of Service
User Offline
Joined: 4th Jun 2018
Location:
Posted: 11th Oct 2022 13:14


I changed again, I went back to using time
but now with some key changes

the initial time starts to be equal to the frametime
and if the frame rate is 30fps then the trail time goes to 2x
this way it keeps the same behaviorat 30, 60 or 999 fps
Arch-Ok
AGK Developer
4
Years of Service
User Offline
Joined: 11th Jul 2019
Location: Bursa/TÜRKIYE
Posted: 13th Oct 2022 22:03
brunuu
5
Years of Service
User Offline
Joined: 4th Jun 2018
Location:
Posted: 13th Oct 2022 22:43
this is a very good implementation
Arch-Ok
AGK Developer
4
Years of Service
User Offline
Joined: 11th Jul 2019
Location: Bursa/TÜRKIYE
Posted: 13th Oct 2022 22:44
And about collision detection, when the frame rate is low, the sprite takes big steps to catch up the time thus gaps occurs. You should check collision between those gaps too maybe by adding small steps. For optimising, firstly just check if sprite bounding boxes are in range, if not then you can completely ignore collision.

Login to post a reply

Server time is: 2024-04-27 02:27:37
Your offset time is: 2024-04-27 02:27:37