[SOLVED] Math problem: Opacity decrease per tick

0 favourites
  • 9 posts
From the Asset Store
Per Pixel Destruction like in "Worms" (perfect performance, no third party plugins)
  • 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? <img src="smileys/smiley5.gif" border="0" align="middle" />

  • 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.

  • Couldn't you just do it like this?

    Every tick set opacity to 100-distance(start.x,start.y,target.x,target.y)

  • 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.

  • if your total distance were other than 100:

    100-(((distance traveled)/(total distance))*100)

  • Crazy maths

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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. >.<


    Each tick

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

    ...to get a smooth opacity decrease from 100 to 0 over my set distance.

  • if your total distance were other than 100:

    100-(((distance traveled)/(total distance))*100)

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

    <img src="http://i.imgur.com/YFlHAmf.png" border="0" />

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)