[SOLVED] Math problem: Opacity decrease per tick

Get help using Construct 2

Post » Thu Aug 15, 2013 1:12 pm

I hate that I'm so lousy at math and this is something i struggle with all the time. In my game i wanted to calculate how much the opacity for my bullet object has to decrease per tick, starting from 100% and going down to zero over a distance of 100 pixels.

Right now i know the following:

Bullet speed: 150 pixels/sec
Travel distance: 100 pixels
Current opacity: 100%
Delta time (dt)

As i understand it, i need to calculate the speed the bullet takes to travel over the set distance which should be time = distance/speed. So 100/150 = 0.66 pixels/sec right?

But this is only how far it moves each second, so to calculate the distance each tick (to get frame based animation) you probably have to do 0.66 * dt? This gives me approx 0.0106 pixels/tick...

This is where it gets confusing and I'm sure that i've approached the whole thing wrong up until now... but how do i know how much the opacity should decrease each tick? hdnine2013-08-16 11:10:42
B
7
S
2
Posts: 38
Reputation: 555

Post » Thu Aug 15, 2013 1:26 pm

@hdnine
Bullet travels 150 pixels per second.
The distance (100 pixels) is travelled over 0.66 seconds.
So the opacity needs to drop from 100 to 0 over 0.66 seconds.
Opacity decreases by 1 every 0.66/100 seconds = 0.0066 seconds.
B
46
S
16
G
74
Posts: 2,089
Reputation: 44,187

Post » Thu Aug 15, 2013 1:47 pm

Couldn't you just do it like this?

Every tick set opacity to 100-distance(start.x,start.y,target.x,target.y)
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Thu Aug 15, 2013 2:36 pm

Since opacity is a percentage and your travel distance happens to be 100, simply setting the opacity every tick to the remaining distance as LittleStain mentionned should work nicely.
B
69
S
28
G
24
Posts: 977
Reputation: 18,739

Post » Thu Aug 15, 2013 2:55 pm

if your total distance were other than 100:

100-(((distance traveled)/(total distance))*100)
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Thu Aug 15, 2013 2:59 pm

Crazy maths
B
46
S
16
G
74
Posts: 2,089
Reputation: 44,187

Post » Thu Aug 15, 2013 5:14 pm

Ok thanks guys... i'll try to figure it out ^^

Thing is that the value 100 is sort of a strength value of how far out the player can shoot a projectile. Right now it's 100 pixels, after which it should be totally faded out and then removed. When the player later on progresses, this value might increase to more like 120 or 150 pixels.

So i'm not to interested in how far it has come, more how many ticks has passed and at what value the opacity should decrease per tick. Maybe they are connected though... right now i'm just crying over my lack of math skills. >.<

So:

Each tick
--> bullet.Opacity = bullet.Opacity - (what?)

...to get a smooth opacity decrease from 100 to 0 over my set distance.hdnine2013-08-15 17:40:36
B
7
S
2
Posts: 38
Reputation: 555

Post » Thu Aug 15, 2013 5:42 pm

if your total distance were other than 100:

100-(((distance traveled)/(total distance))*100)
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Fri Aug 16, 2013 11:10 am

Just to let everyone know, this is how i solved the issue:

B
7
S
2
Posts: 38
Reputation: 555


Return to How do I....?

Who is online

Users browsing this forum: Baidu [Spider], brunopalermo, dop2000, jorgmaquoi, kiki4construct and 27 guests