Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Looking for Inertia Help

Author
Message
Marabas
15
Years of Service
User Offline
Joined: 12th Dec 2010
Location:
Posted: 26th Jun 2012 22:57 Edited at: 26th Jun 2012 23:13
OK I have looked at the other posts involving inertia and they seemed a little complex for me so I came up with a simple solution to double the speed until we arrive at maximum speed and do the opposite until we arrive back at idle speed.

This is what I have so far



The problem is that when I double the speed it will only do it once and then doesn't even bother to look if a key is pressed. How can I get it to double the speed each sync? I'm not worried aboutthe numbers for now because I will fiddle with the max and min values until they are right.

I have attached the background so you can try this if you are kind enough to help.

EDIT: I have just tried using keystate instead of scancode but still hit the same problem, the value only doubles once ???

Signature removed by moderator. Please do not give out the meaning of life in an open forum.
Pincho Paxton
23
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 26th Jun 2012 23:16
with this at the top ..... sc_spd#=0.001

You keep resetting the speed. You need to get rid of it from the loop, or not trigger it when a key is pressed.

29 games
20
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 26th Jun 2012 23:18
Hi Marabas

Delete the line "sc_spd#=0.001" after the DO and you'll reach maximum speed. It's reseting the value sc_spd# at the start of the loop and giving the issue you describe.

Once you've done this, you'll probably find that doubling the speed each loop is too fast so you'll have to play with the numbers to get a noticable accelertion..

Other options would be to use to use an addition formula i.e. speed = speed + constant_value or use the CURVEVALUE commands.

I can't give a preference as I don't have one. All that really counts is that you get a nice smooth effect.
Marabas
15
Years of Service
User Offline
Joined: 12th Dec 2010
Location:
Posted: 26th Jun 2012 23:47 Edited at: 26th Jun 2012 23:56
Thanks, I'm dumb sometimes...

My code has now kind of evolved to this



problem is that it just stops dead rather than slowing to a stop. I have tried all sorts of values to divide by but even at 1.0001 the scroll doesn't slow to a stop it just stops dead.

Any ideas why it might be doing this?

EDIT:
Hmmm CURVEVALUE looks like it could be useful, thank you 29 Games. I can understand the destination and current values but if I was using CURVEVALUE 0.001, 0.008, ?????? what might the speed value be? Or maybe I will experiment and report back

Signature removed by moderator. Please do not give out the meaning of life in an open forum.
29 games
20
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 27th Jun 2012 00:28 Edited at: 27th Jun 2012 01:06
With the formula you're using it will just stop dead. To illustrate:

If you start with speed = 1 then let's say you double the speed each loop, so speed = speed*2, then the speed increases like this:

1st loop: speed = 1
2nd loop: speed = 2
3rd loop: speed = 4
4th loop: speed = 8
5th loop: speed = 16
6th loop: speed = 32

and so on until the maximum speed is reached. But what you can see is that you get big leaps in speed toward the end, the speed is increasing exponentially. This is why the speed doesn't slowly reach the maximum value.

If you use: speed = speed + constant_value, you'll get a linear increase in speed. If the constant_value = 6 then:

1st loop: speed = 0
2nd loop: speed = 6
3rd loop: speed = 12
4th loop: speed = 18
5th loop: speed = 24
6th loop: speed = 32

If you want a big jump in speed at the start and then a slower increases as it reaches maximum speed:

1st loop: speed = 1
2nd loop: speed = 17
3rd loop: speed = 25
4th loop: speed = 29
5th loop: speed = 31
6th loop: speed = 32

then you need a different formula, which I can't quite get my head round at the moment [see edit at bottom of post]. However, the CURVEVALUE command will give you this effect.



What you'll notice is that, what ever you change max_speed# to, it'll take the same amount of time to reach it. One thing to bare in mind is the the "speed value" of the curve value command needs to be high if you want a slow transition.

Edit: for the sake of completeness, the formula is: speed = speed + 0.5*(max_speed - speed + 1). Where, in this example, max_speed = 32.
Marabas
15
Years of Service
User Offline
Joined: 12th Dec 2010
Location:
Posted: 27th Jun 2012 01:49
WOW thank you so much, I have been fiddling with CURVEVALUE but couldn't get my head round it and the help files really don't, erm, help LOL

I will try to incorporate this into my code and see how it goes.

Signature removed by moderator. Please do not give out the meaning of life in an open forum.
Marabas
15
Years of Service
User Offline
Joined: 12th Dec 2010
Location:
Posted: 27th Jun 2012 02:48
OK, I got it now. I will post it here in case anyone else has a similar problem. Big thanks to 29 Games for helping me to solve this. It moved a long way from my original puny code.

Please note that this code only scrolls the texture background, you would have to add the speed# to your object to get it to move in the x or y directions. Anyway, here's the code, the texture is in the OP at the top.



Signature removed by moderator. Please do not give out the meaning of life in an open forum.

Login to post a reply

Server time is: 2026-07-07 17:08:31
Your offset time is: 2026-07-07 17:08:31