Agus98
(Agus98)
November 18, 2014, 2:32pm
1
Hi, this is more of a general python question rather than game engine, but anyways…
i have two values: MAX , X , and Y
I want to continuously add (or subtract) Y to X until it reaches MAX
I already tried this:
own[“X”] += Y* math.copysign(1 ,abs(own[“MAX”])- abs(own[“X”]))
but it won’t work if MAX is negative.
Please help me.
skywola
(skywola)
November 18, 2014, 4:26pm
2
Try this:
x = -144
y = 2
max = -100
while x < max:
x = x + y
print(str(x))
Agus98
(Agus98)
November 18, 2014, 4:41pm
3
It doesn’t work, it reaches max instantly, and I want it to reach it gradually.
Thats because your computer is fast… you need to add in a sleep function
import time
x = -144
y = 2
max = -100
while x < max:
x = x + y
print(str(x))
time.sleep(1)
skywola
(skywola)
November 18, 2014, 6:37pm
5
Insert a sleep command . . .
import time
y = 0
x = 44
y = 2
duration = .1
max = 100
while x < max:
x = x + y
time.sleep(duration)
print(str(x))
Just change duration for make it go for whatever time you want it to take. You will not be able to run any other
functions until the while loop has finished, and the sleep command will execute each time the while loop runs, so do not make duration to long.
CoDEmanX
(CoDEmanX)
November 19, 2014, 1:23am
6
in game engines, you would usually use a formula that contains a time variable supplied by the engine and return the current location / value…
Agus98
(Agus98)
November 19, 2014, 9:46am
7
I tried this:
while own["value"] < own["maxvalue"]:
own["value"] = own["value"] + 2
time.sleep(1)
I don’t need to print anything because I’m just using debug properties
Blender freezes.
Agus98
(Agus98)
November 19, 2014, 10:48am
8
Never mind, i just figured it out
own["X"] += Y* math.copysign(1, own["MAX"] - own["X"])