Gamestudio Links
Zorro Links
Newest Posts
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
Trading Journey
by howardR. 04/28/24 09:55
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (Quad, Ayumi, AndrewAMD), 1,092 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 3 1 2 3
Exponential increase/decrease using time_step... #240867
12/12/08 23:34
12/12/08 23:34
Joined: Nov 2007
Posts: 50
C
Chaeon Offline OP
Junior Member
Chaeon  Offline OP
Junior Member
C

Joined: Nov 2007
Posts: 50
im trying to achieve camera movement that deceases in speed the closer the camera gets to its optimum position, above the player model. the obvious way to go about this is by subtracting a percentage of the remaining distance to cover from the camera's position:

camera.x -= .02 * (camera.x - intended.x);
camera.y -= .02 * (camera.y - intended.y);

this is nice and smooth, but the camera would move around faster on faster hardware, and just multiplying the percentage by time_step doesn't work because the problem deals with exponents(and subtracting a percentage twice as big with half the frequency yeilds different results). Any ideas on how to factor time_step into an exponential increase or decrease?
thanks people!

btw this problem pops up in several places in my project, the camera scenario's just the easiest way to explain it.

Last edited by Chaeon; 12/14/08 01:19.
Re: Exponential increase/decrease of a value... [Re: Chaeon] #240894
12/13/08 08:30
12/13/08 08:30
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
camera.x -= .02 * (intended.x - camera.x) * time_step;
camera.y -= .02 * (intended.y - camera.y) * time_step;

You may need to increase the 0.02 to get the old feel(probably about 0.1), but
it will now be stable across all hardware speeds, once you found that number for yours.


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: Exponential increase/decrease of a value... [Re: EvilSOB] #241024
12/13/08 23:02
12/13/08 23:02
Joined: Nov 2007
Posts: 50
C
Chaeon Offline OP
Junior Member
Chaeon  Offline OP
Junior Member
C

Joined: Nov 2007
Posts: 50
Thanks for your reply evilSOB

But the point of the question is that just poking time_step in DOESN'T work, because subtracting a percentage of a number once a second (for example) produces a faster decrease than subtracting a quarter of that percentage four times a second, right? So normal time_step doesn't work.

I think the answer would have something to do with multiplying a power by time_step, but i don't know how it would work. I'll keep thinking but any suggestions are appreciated.


I HEART 3DGS
Re: Exponential increase/decrease of a value... [Re: Chaeon] #241029
12/14/08 00:03
12/14/08 00:03
Joined: May 2002
Posts: 7,441
ventilator Offline
Senior Expert
ventilator  Offline
Senior Expert

Joined: May 2002
Posts: 7,441
Quote:
because subtracting a percentage of a number once a second (for example) produces a faster decrease than subtracting a quarter of that percentage four times a second, right?
no, why do you think so? simply multiplying time_step works fine.

Re: Exponential increase/decrease of a value... [Re: ventilator] #241039
12/14/08 01:16
12/14/08 01:16
Joined: Nov 2007
Posts: 50
C
Chaeon Offline OP
Junior Member
Chaeon  Offline OP
Junior Member
C

Joined: Nov 2007
Posts: 50
Because:

(assume target camera x position is 0, and assume camera.x is twenty)

faster machine: time_step = 4:

camera.x -= .02 * (camera.x - 0) * 4;

wait(1); // camera.x now equals 18.4

camera.x -= .02 * (camera.x - 0) * 4;

wait(1); // camera.x now equals 16.928

camera.x -= .02 * (camera.x - 0) * 4;

wait(1); // camera.x now equals 15.57376

camera.x -= .02 * (camera.x - 0) * 4;

wait(1); // an amount of time has passed. camera.x now equals 14.3278592

final camera.x after one second on faster machine is 14.3278592



slower machine: time_step = 2:

camera.x -= .02 * (camera.x - 0) * 2;

wait(1); // camera.x now equals 19.2

camera.x -= .02 * (camera.x - 0) * 2;

wait(1); // same amount of time has passed. camera.x now equals 18.432

final camera.x after one second on slower machine is 18.432

hence decrease of camera.x is greater on faster computers if you use

camera.x -= .02 * (camera.x - 0) * time_step;


well i was wrong when i said that a faster machine would produce slower camera movement (mostly due to the painfully noobish assumption that time_step reflects the number of frames that occurred in the last second), but the point remains the same. Because i'm dealing with exponents the usual means of implementing time_step doesn't work. I've really got some thinking to do. Perhaps i should start a new thread, as ive made such a mess of this one? Nah ill just correct the first post


I HEART 3DGS
Re: Exponential increase/decrease of a value... [Re: Chaeon] #241042
12/14/08 01:43
12/14/08 01:43
Joined: Oct 2006
Posts: 36
BigM Offline
Newbie
BigM  Offline
Newbie

Joined: Oct 2006
Posts: 36
camera.x += (target.x - camera.x) * pow(reductionpersecond,16/time_step)

target.x is the target camera position (0 in your example).
reductionpersecond is the percentage of the distance that should be covered each second.

Last edited by BigM; 12/14/08 01:44.
Re: Exponential increase/decrease of a value... [Re: BigM] #241048
12/14/08 02:56
12/14/08 02:56
Joined: Nov 2007
Posts: 50
C
Chaeon Offline OP
Junior Member
Chaeon  Offline OP
Junior Member
C

Joined: Nov 2007
Posts: 50
great!!! i knew there must be something! thanks so much bigM you are a genius. ill try it out now, it looks correct...


I HEART 3DGS
Re: Exponential increase/decrease of a value... [Re: Chaeon] #241061
12/14/08 05:12
12/14/08 05:12
Joined: Nov 2007
Posts: 50
C
Chaeon Offline OP
Junior Member
Chaeon  Offline OP
Junior Member
C

Joined: Nov 2007
Posts: 50
one question though, out of curiosity..

where does the 16 come from? i thought a tick was a sixteenth of a second, but this formula has nothing to do with ticks, or does it?


I HEART 3DGS
Re: Exponential increase/decrease of a value... [Re: Chaeon] #241062
12/14/08 05:39
12/14/08 05:39
Joined: Oct 2004
Posts: 1,655
T
testDummy Offline
Serious User
testDummy  Offline
Serious User
T

Joined: Oct 2004
Posts: 1,655
It seems ventilator is correct, with precision being a consideration.

Try reversing 2 and 4 (above in example calcs).



Re: Exponential increase/decrease of a value... [Re: BigM] #241065
12/14/08 09:11
12/14/08 09:11
Joined: Nov 2007
Posts: 50
C
Chaeon Offline OP
Junior Member
Chaeon  Offline OP
Junior Member
C

Joined: Nov 2007
Posts: 50
nooo! bigM's formula doesn't seem to work, and I have no idea how to adjust it because i don't know how it works because it has that mysterious 16 in it!


I HEART 3DGS
Page 1 of 3 1 2 3

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1