Programming a rhythmic increase/decrease of a value

Discuss programming in the QuakeC language.
Post Reply
OneManClan
Posts: 247
Joined: Sat Feb 28, 2009 2:38 pm
Contact:

Programming a rhythmic increase/decrease of a value

Post by OneManClan »

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.
necros
Posts: 77
Joined: Thu Dec 16, 2004 10:32 pm

Post by necros »

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:

Code: Select all

.float hookImpulseTime;
in the hook pull code loop, you'll need to add a new local float

Code: Select all

local float mult;
and a constant we can mess around with easily:

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;
this will reset hookImpulseTime time+1 every time it expires. this will send a velocity impulse every second.

next we set up the multiplier:

Code: Select all

mult = (self.hookImpulseTime - time) / interval;
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.

Code: Select all

mult = 1 - mult;
now, we just apply this multiplier to the velocity vector.

Code: Select all

player.velocity = normalizedHookPullDirectionVector * maxSpeed * mult;
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.
OneManClan
Posts: 247
Joined: Sat Feb 28, 2009 2:38 pm
Contact:

Post by OneManClan »

necros wrote: try something like this:
...
Thanks necros,

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;	
And added a bit to make it not actually stop (during the slow bits)

Code: Select all

if (mult < 0.2) mult = 0.2;
It's working well, and I might add a 'grunt' to the 'pulling' part.


thanks again,


OneManClan
r00k
Posts: 1111
Joined: Sat Nov 13, 2004 10:39 pm

Post by r00k »

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.
OneManClan
Posts: 247
Joined: Sat Feb 28, 2009 2:38 pm
Contact:

Post by OneManClan »

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?
Hi r00k,

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.
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.
Interesting idea.
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.
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.


OneManClan
frag.machine
Posts: 2126
Joined: Sat Nov 25, 2006 1:49 pm

Post by frag.machine »

OneManClan wrote:
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?
Hi r00k,

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.
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).
I know FrikaC made a cgi-bin version of the quakec interpreter once and wrote part of his website in QuakeC :) (LordHavoc)
mankrip
Posts: 924
Joined: Fri Jul 04, 2008 3:02 am

Post by mankrip »

You could make like UT does with the translocator, making the flag carrier automatically drop the flag if he uses the grapple.
Ph'nglui mglw'nafh mankrip Hell's end wgah'nagl fhtagn.
==-=-=-=-=-=-=-=-=-=-==
Dev blog / Twitter / YouTube
OneManClan
Posts: 247
Joined: Sat Feb 28, 2009 2:38 pm
Contact:

Post by OneManClan »

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).
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.
mankrip wrote:You could make like UT does with the translocator, making the flag carrier automatically drop the flag if he uses the grapple.
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.

Thanks for the feedback!
r00k
Posts: 1111
Joined: Sat Nov 13, 2004 10:39 pm

Post by r00k »

I havent played th emod, but i'd imagine that each team could have two hookers, one for offense one for defense...
Spike
Posts: 2914
Joined: Fri Nov 05, 2004 3:12 am
Location: UK
Contact:

Post by Spike »

r00k, are you sure two hookers are enough for your average team of gamers?
mankrip
Posts: 924
Joined: Fri Jul 04, 2008 3:02 am

Post by mankrip »

:lol:
Ph'nglui mglw'nafh mankrip Hell's end wgah'nagl fhtagn.
==-=-=-=-=-=-=-=-=-=-==
Dev blog / Twitter / YouTube
frag.machine
Posts: 2126
Joined: Sat Nov 25, 2006 1:49 pm

Post by frag.machine »

mankrip wrote:You could make like UT does with the translocator, making the flag carrier automatically drop the flag if he uses the grapple.
This.
I know FrikaC made a cgi-bin version of the quakec interpreter once and wrote part of his website in QuakeC :) (LordHavoc)
Post Reply