Programming a rhythmic increase/decrease of a value
-
- Posts: 247
- Joined: Sat Feb 28, 2009 2:38 pm
- Contact:
Programming a rhythmic increase/decrease of a value
Hi all, this is kind of hard to explain..
OBJECTIVE: Currently players on a grappling hook (qw hook.qc) move at a set speed whilst on the hook. I want the speed to vary, specifically (once a second) slow down, and revert to normal speed.
So the grappler moves in little bursts. To do this I (presumably) need to alter the value of his speed. I need a new function which takes a value (the players speed) smoothly decreases it, and then smoothly increases it (back to the original value), every second.
The only comparative example I can think of in the real world is to imaging you are in a car and press the accelerator every second. OR the cars engine is failing and you get these bursts of power every second, and the car jerkily stumbles forward.
Does anyone have any ideas / suggestions on how to vary a value in this way?
thanks,
OneManClan
ps and if someone can think of a better/clearer description in the subject line, please let me know.
OBJECTIVE: Currently players on a grappling hook (qw hook.qc) move at a set speed whilst on the hook. I want the speed to vary, specifically (once a second) slow down, and revert to normal speed.
So the grappler moves in little bursts. To do this I (presumably) need to alter the value of his speed. I need a new function which takes a value (the players speed) smoothly decreases it, and then smoothly increases it (back to the original value), every second.
The only comparative example I can think of in the real world is to imaging you are in a car and press the accelerator every second. OR the cars engine is failing and you get these bursts of power every second, and the car jerkily stumbles forward.
Does anyone have any ideas / suggestions on how to vary a value in this way?
thanks,
OneManClan
ps and if someone can think of a better/clearer description in the subject line, please let me know.
i don't know the qw hook code at all, so this is just a rough guess. you'll have to work this into your code.
try something like this:
create a variable you'll use as a timer:
in the hook pull code loop, you'll need to add a new local float
and a constant we can mess around with easily:
what you're going to do is:
this will reset hookImpulseTime time+1 every time it expires. this will send a velocity impulse every second.
next we set up the multiplier:
this will create a value that starts at 0 and increases to 1 as time approaches self.hookImpulseTime.
obviously though, this will give an INCREASING impulse, which isn't what you wanted, so we just invert it.
now, we just apply this multiplier to the velocity vector.
you can change the way it behaves by changing the interval variable smaller for quicker jolts.
you can also try squaring or cubing mult to quicker speed falloff.
try something like this:
create a variable you'll use as a timer:
Code: Select all
.float hookImpulseTime;
Code: Select all
local float mult;
Code: Select all
local float interval;
interval = 1.0;
what you're going to do is:
Code: Select all
if (time > self.hookImpulseTime)
self.hookImpulseTime = time + interval;
next we set up the multiplier:
Code: Select all
mult = (self.hookImpulseTime - time) / interval;
obviously though, this will give an INCREASING impulse, which isn't what you wanted, so we just invert it.
Code: Select all
mult = 1 - mult;
Code: Select all
player.velocity = normalizedHookPullDirectionVector * maxSpeed * mult;
you can also try squaring or cubing mult to quicker speed falloff.
-
- Posts: 247
- Joined: Sat Feb 28, 2009 2:38 pm
- Contact:
Thanks necros,necros wrote: try something like this:
...
I had to fiddle with the values till it looked natural for players who moved at different speeds (yes if my maths was better I'm sure this could have been expressed w a formula):
Code: Select all
if (self.maxspeed > 600) interval = 0.3;
else
if (self.maxspeed > 500) interval = 0.5;
else
if (self.maxspeed > 400) interval = 0.7;
else
if (self.maxspeed > 300) interval = 0.9;
else
interval = 1.1;
Code: Select all
if (mult < 0.2) mult = 0.2;
thanks again,
OneManClan
Honestly, as an avid CTF player this would make me quit playing your mod after one game. What's the purpose of a herky-jerky hook?
If you just want to curve the speed rate the velocity of the pull based on the distance of the chain. So as the player reaches the halfway point he can be at full speed then decelerate as the hook gets closer. If you are just trying to limit the overall speed of the game by limiting the hook, then you can limit the distance the hook could be thrown.
If you just want to curve the speed rate the velocity of the pull based on the distance of the chain. So as the player reaches the halfway point he can be at full speed then decelerate as the hook gets closer. If you are just trying to limit the overall speed of the game by limiting the hook, then you can limit the distance the hook could be thrown.
-
- Posts: 247
- Joined: Sat Feb 28, 2009 2:38 pm
- Contact:
Hi r00k,r00k wrote:Honestly, as an avid CTF player this would make me quit playing your mod after one game. What's the purpose of a herky-jerky hook?
It's purpose is to (help) solve an existing problem in AGR CustomTF gameplay. I don't know how the grapple affects CTF, but Grapplers in AGR force Blue to split their Defense, and assign one or even two players just to cover the paths that only a grappler could access. On some BIG, 'hard to defend' maps (eg sewer1p) this can make life (almost) impossible for Blue; accordingly, the original CustomTF programmers simply disabled the grapple for certain maps. I'd rather have it in, but make it more risky/difficult/challenging to use. If you'd been playing at the Weekly AGR Sessions, and seen an ultra Tanky Red grappler bypass the main area of a base, then 'fly away' with the flag, sustaining damage from multiple Blue Defenders trying (in vain) to stop him, you'd understand.
Btw, the original intention for the 'rhythmic speed variation' (as discussed in this thread) was to make it HARDER for the grappler, because it is slower than normal, BUT (!!) preliminary gameplay testing has revealed that it actually makes life easier, because the grappler becomes harder to hit(!). I'm not sure if I'll add this to the list of Grapple adjustments at this stage; maybe make a more extreme version that only affects flag carriers, or injured players. In any case, the whole thing will be adjusted so that it ‘feels fair’ to everyone.
Interesting idea.r00k wrote:If you just want to curve the speed rate the velocity of the pull based on the distance of the chain. So as the player reaches the halfway point he can be at full speed then decelerate as the hook gets closer.
Yes, this does make sense. It does seem 'unnatural' that the Grapple device can throw a perfectly straight line, unaffected by gravity, at unlimited distances. Otoh this has been a part of the basic functionality of the grapple from day 1, and a majority of AGR players are still CustomTF fans, and in spite of the many changes, I want the mod to remain comfortable/familiar to them, as much as possible.r00k wrote:If you are just trying to limit the overall speed of the game by limiting the hook, then you can limit the distance the hook could be thrown.
OneManClan
-
- Posts: 2126
- Joined: Sat Nov 25, 2006 1:49 pm
Nerfing an existing weapon will piss off players used to it. Instead, try to tweak the map geometry, or maybe create some kind of "hook counter measure" (for example, a tranquilizer dart that slows the Tarzan wannabes).OneManClan wrote:Hi r00k,r00k wrote:Honestly, as an avid CTF player this would make me quit playing your mod after one game. What's the purpose of a herky-jerky hook?
It's purpose is to (help) solve an existing problem in AGR CustomTF gameplay. I don't know how the grapple affects CTF, but Grapplers in AGR force Blue to split their Defense, and assign one or even two players just to cover the paths that only a grappler could access. On some BIG, 'hard to defend' maps (eg sewer1p) this can make life (almost) impossible for Blue; accordingly, the original CustomTF programmers simply disabled the grapple for certain maps. I'd rather have it in, but make it more risky/difficult/challenging to use. If you'd been playing at the Weekly AGR Sessions, and seen an ultra Tanky Red grappler bypass the main area of a base, then 'fly away' with the flag, sustaining damage from multiple Blue Defenders trying (in vain) to stop him, you'd understand.
I know FrikaC made a cgi-bin version of the quakec interpreter once and wrote part of his website in QuakeC (LordHavoc)
-
- Posts: 247
- Joined: Sat Feb 28, 2009 2:38 pm
- Contact:
Yes, I've made some changes to the Grapple which have already pissed off some players (Grapplers) , but otoh, others (those trying to stop them) were like 'cool, about time something was done', so it's not easy pleasing everyone.frag.machine wrote:Nerfing an existing weapon will piss off players used to it. Instead, try to tweak the map geometry, or maybe create some kind of "hook counter measure" (for example, a tranquilizer dart that slows the Tarzan wannabes).
Hmm .. Grapplers grapple all the way to the flag, ..but not Grapple out with the flag. This sounds like a VERY reasonable compromise. This will take some pressure off (eg) the lift area in 2fort5r. Nice.mankrip wrote:You could make like UT does with the translocator, making the flag carrier automatically drop the flag if he uses the grapple.
Thanks for the feedback!
-
- Posts: 2126
- Joined: Sat Nov 25, 2006 1:49 pm