generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Time proportional to difference? Help please?

Previous Thread :: Next Thread 
xiaoxiao181 is not online. xiaoxiao181
Joined: 14 Aug 2008
Total Posts: 5882
14 Aug 2013 01:01 AM
I'm trying to think of a math formula for a wait() interval that is dependent on the difference between Value and MaxValue of an IntConstrainedValue and then use that to set the tweening time of a gui.

More specifically, I made a health gui. Unlike other health guis that resize themselves instantly when the health is changed, I want to use the tweening method. For this, I want to be able to automatically change the wait time during the tweening process. For this example the MaxValue is 100. If, let's say, the Value is 20 and I use a potion to restore full health. This means the difference is 80. I want the wait time to be slower than if say, the difference was 20 where it would instead be quicker. The reason is because regardless of the float time, even if the easing style is linear, the gui resizes in the opposite way, where it resizes faster if the change is larger than if the change was smaller. That means that on its own, the gui was resize faster if it has to make alarger change, and slightly slower than if it has to make a slight change. Basically it changes its speed to make sure it completes the resize in 0.5 seconds.

I simply need a math formula that can change the float time based on the amount of change, so that the gui resizes at exactly the same speed regardless of the amount of change it needs to make. So if the difference between the Value and MaxValue is 80, it changes the float time to make the gui resize slower. If the difference is 20, it makes the gui resize faster. So, whatever the difference between Value and MaxValue is, the gui should VISUALLY resize at the same speed.
Report Abuse
BJCarpenter is online. BJCarpenter
Joined: 04 Nov 2008
Total Posts: 4416
14 Aug 2013 01:14 AM
/
Report Abuse
xiaoxiao181 is not online. xiaoxiao181
Joined: 14 Aug 2008
Total Posts: 5882
14 Aug 2013 01:17 AM
? o.o I'm not sure how a slash helps, but to each their own I s'pose.
Report Abuse
dog456pop248 is not online. dog456pop248
Joined: 24 Aug 2008
Total Posts: 3977
14 Aug 2013 01:18 AM
I don't think I can help, but I need to clarify...

So basically you want tweening from 20 to 100
and 20 to 50 to be the same speed, and you need a formula that's consistent?
Report Abuse
xiaoxiao181 is not online. xiaoxiao181
Joined: 14 Aug 2008
Total Posts: 5882
14 Aug 2013 01:29 AM
Yes, that's exactly it. I explained it absolutely wrong, but you hit the nail on the head.

The gui tweening should remain at a constant speed, regardless of how much the health is increased or decreased.
Report Abuse
dog456pop248 is not online. dog456pop248
Joined: 24 Aug 2008
Total Posts: 3977
14 Aug 2013 01:36 AM
Aaaand 2 paragraph post turned into a 2 sentence post.
Hopefully anyone who knows how to help can better help you now.
Report Abuse
dennis96411 is not online. dennis96411
Joined: 06 Mar 2009
Total Posts: 1079
14 Aug 2013 01:44 AM
Do you really need a math formula for this? I might not be understanding this correctly. Are you saying you want the change to be the same SPEED or same DURATION? If duration, then just find your sweet spot for how long you want it to change, then figure out a ratio.
Report Abuse
dog456pop248 is not online. dog456pop248
Joined: 24 Aug 2008
Total Posts: 3977
14 Aug 2013 01:47 AM
I believe she means duration
Report Abuse
xiaoxiao181 is not online. xiaoxiao181
Joined: 14 Aug 2008
Total Posts: 5882
14 Aug 2013 02:08 AM
No I mean speed. :)

Let me try to make a better example using real life driving speed as a way of explaining it.

If the float time is 0.5, and the healthbar changes from 100% to 0%, the gui then travels at about 50 MPH. If the gui changes from 100% to 50%, the gui travels at 25 MPH. See where I'm going with this? While the time it takes for the gui to tween remains the same, the speed of the gui changes. I want a math formula to make it do the exact opposite. I want the time to change, while the speed remains constant.
Report Abuse
dennis96411 is not online. dennis96411
Joined: 06 Mar 2009
Total Posts: 1079
14 Aug 2013 02:12 AM
Alright, let's see what I can come up with. So let's say you want to transit from 20 to 80 in 10 seconds (the same duration for all change).
Difference: 80 - 20 = 60
Duration: 60 / x = 10 seconds

So as you can see, to get the speed, we need to first set how fast we want the total duration (x) to be, and we need to use the formula (MaxValue - Value) / x = 10. Solving for x will give us the change per second.
x = (MaxValue - Value) / 10

So let's say I want to transit from 30 to 70 in 10 seconds as well.
x = (70 - 30) / 10 = 4 per second

Am I doing this correctly?
Report Abuse
dennis96411 is not online. dennis96411
Joined: 06 Mar 2009
Total Posts: 1079
14 Aug 2013 02:21 AM
Ah, ignore that last post, I didn't get to read your new post. If we're talking about speed, then let's say we want to transit from 20 to 80 in 10 seconds.
Difference: 80 - 20 = 60
Speed: 60 / 10 = x = 6 per second

So we now know the speed (x) is 6 per second. Let's say we now want to transit from 30 to 70 at the same speed.
Difference: 70 - 30 = 40
Speed: 40 / y = x = 6 per second

Solving for y will give you the duration to transit from 30 to 70 so that the speed is 6 per second, same as the above.
y = 40 / x = 40 / 6 = 6.66 seconds total

So to make sure that all transition have the same speed, use the following formula:
x = Speed, y = Duration
y = (MaxValue - Value) / x

All you need to do is set your own speed, and let the function calculate the duration. If my math is wrong, then sorry, I haven't played with any numbers for awhile (although I've recently passed the AP Calculus AB exam with a 5).
Report Abuse
xiaoxiao181 is not online. xiaoxiao181
Joined: 14 Aug 2008
Total Posts: 5882
14 Aug 2013 11:52 AM
I think my brain just farted and died. O_o
Report Abuse
xiaoxiao181 is not online. xiaoxiao181
Joined: 14 Aug 2008
Total Posts: 5882
14 Aug 2013 11:59 AM
I guess I can just uhh... let it snap instantly and figure it out some other day when I have a better understanding of wtf you just said. O_o
Report Abuse
MHebes is not online. MHebes
Joined: 04 Jan 2013
Total Posts: 2278
14 Aug 2013 12:03 PM
Just do something like this:

speed = distance/time
distance = speed*time
time = distance/speed
bar = GuiBar
maxSize = 200
speed = 10 -- Idk, change
health = 100
maxHealth = 100

function onChanged()
bar:TweenSize(UDim2.new(0,maxSize*(health/maxHealth),bar.Size.Y.Scale,bar.Size.Y.Offset),"Out","Linear",(maxSize-bar.Size.X.Offset)/speed,true)--may need to be false, I forget
end

~ Oh, I'm sorry, did I break your concentration? ~
Report Abuse
MHebes is not online. MHebes
Joined: 04 Jan 2013
Total Posts: 2278
14 Aug 2013 12:04 PM
Those first 3 lines were for my reference, you don't need them, forgot to delete them :P

~ Oh, I'm sorry, did I break your concentration? ~
Report Abuse
blocco is not online. blocco
Joined: 14 Aug 2008
Total Posts: 29474
14 Aug 2013 12:12 PM
It shouldn't be that hard to figure out. Just change the time taken to tween relative to the change of health.
Report Abuse
xiaoxiao181 is not online. xiaoxiao181
Joined: 14 Aug 2008
Total Posts: 5882
14 Aug 2013 12:24 PM
I've decided it's too much trouble to bother with. :/ I'll just let it snap instantly and deal with it some other day. >_<
Report Abuse
MHebes is not online. MHebes
Joined: 04 Jan 2013
Total Posts: 2278
14 Aug 2013 12:26 PM
But...

time = distance/speed

How is that difficult? Also, I gave you the script ._.

~ Oh, I'm sorry, did I break your concentration? ~
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image