View previous topic :: View next topic |
Author |
Message |
OneManClan
Joined: 28 Feb 2009 Posts: 62
|
Posted: Sun Apr 26, 2009 5:04 am Post subject: Help: Programming a 'forcefield' ability |
|
|
DISCLAIMER: This is not a 'high priority' mod, it's just a 'fun' optional extra I'd like to add to AGR CustomTF. I present it as an example of a mod where I have no idea where to begin, and I'm curious as to how someone skilled would approach the solution.
Hi guys,
In CustomTF there's a skill called 'Chaplain', where you put down your weapon, sing/preach, glow, and give quad power to all teammates within a certain radius of you. I'd like to add the following:
1. Whilst 'chapping' you have a 'forcefield'. No enemy can come within x distance of you. There's an impenetrable, invisible bubble around you. I don't know how to measure distances in Quake, but say a radius of 'one shambler'.
2. When you move towards enemies, they are pushed back! They 'part' for you. If they CAN'T be pushed back (eg they're against a wall) then you can't move closer to them. A radius of 'personal space' cannot be breached.
Note: The forcefield only affects the players 'bodies'. Their sentries, non-human monsters, bullets, grenades etc etc can pass through. This protects the chaplain from melee damage (axes, knives, mauser, spanner etc)
I realise this is advanced, but I'd appreciate some direction - ie where do I begin? Off the top of my (newbie) head:
We need an entity do be the forcefield
It will need an attribute 'radius'
It will need to be non-solid so the owner (and teammates) can be inside it?
It will need a touch function for when enemies are at it's border?
Regarding the 'push enemies away' part..
Um... er... well..
..There is a 'knocktation effect' used to make players bodies go backwards when your weapon touches them..??
.. the rate of 'recoil' (?) can just be equivalent to the chaplains speed at the time of impact...(?) ie if he's walking at x speed towards you, you get pushed back at x speed .
Ideally the enemies should move backwards in sync with the chaps movements, but if this isn't possible, maybe there could be a gust of wind BLOWING the enemy players away (?)
Ideas, suggestions or feedback welcome.
thanks,
OneManClan |
|
Back to top |
|
 |
scar3crow Inside3D Staff

Joined: 18 Jan 2005 Posts: 837 Location: Las Vegas, NV
|
Posted: Sun Apr 26, 2009 5:53 am Post subject: |
|
|
I suggest looking at the trigger_push code, which knocks players around. The chaplain could just emanate a similar function, only it performs a team check first before proceeding. Regarding pushing away the chaplain if the enemy is near a wall, perhaps there could be a check for redundant presence, if the push is sufficient, the enemy player shouldn't STILL be in the radius of the forcefield half a second later, but if they are, it would seem something is stopping them from being pushed, if so, inverse the angles and push the chaplain in that direction, to maintain the distance. I think the trick here would be checking that it is the same player, so multiple enemies coming close couldn't launch the chaplain away with their own forcefield. _________________ ...and all around me was the chaos of battle and the reek of running blood.... and for the first time in my life I knew true happiness. |
|
Back to top |
|
 |
OneManClan
Joined: 28 Feb 2009 Posts: 62
|
Posted: Sun Apr 26, 2009 6:16 am Post subject: |
|
|
scar3crow wrote: | I suggest looking at the trigger_push code, which knocks players around. The chaplain could just emanate a similar function, only it performs a team check first before proceeding. |
Thanks, I'll look into it.
scar3crow wrote: | Regarding pushing away the chaplain if the enemy is near a wall, |
Sorry if I was unclear... The chaplain never gets 'pushed'. If the enemy is near a wall, the enemy gets pushed back, until he cant be pushed back further, and then the chap can't move closer to him, and stays at the radius of the forcefield. If the enemy is pushed into a corner for example, he gets stuck. He can't move until the chap moves backwards, or to the side.
What happens when two (opposing) Chaplains meet? They stay at the distance of their combined forcefields radius's (radii?). Neither can push the other so the physics should be the same as two 'regular players', except that the 'size' of each chaplain includes the forcefield itself.
I hope my description makes sense.
thanks,
OneManClan |
|
Back to top |
|
 |
scar3crow Inside3D Staff

Joined: 18 Jan 2005 Posts: 837 Location: Las Vegas, NV
|
Posted: Sun Apr 26, 2009 6:38 am Post subject: |
|
|
Well I was suggesting that the push be done to maintain that distance - I don't know of a way to create an arbitrary but permanent collision for the chaplain in regards to enemies, without it impacting other players... The push back on the chaplain would just be to, if he knocks an enemy into a corner, to keep him from getting any closer than he already was.
Or you could just be significantly hacky and give the chaplain the collision hull of a shambler, so he couldn't fit through doors, and would be easier to hit... ...and thus it wouldn't really be worth now that I type it out so hey =) _________________ ...and all around me was the chaos of battle and the reek of running blood.... and for the first time in my life I knew true happiness. |
|
Back to top |
|
 |
OneManClan
Joined: 28 Feb 2009 Posts: 62
|
Posted: Sun Apr 26, 2009 4:25 pm Post subject: |
|
|
scar3crow wrote: | Well I was suggesting that the push be done to maintain that distance - I don't know of a way to create an arbitrary but permanent collision for the chaplain in regards to enemies, without it impacting other players... The push back on the chaplain would just be to, if he knocks an enemy into a corner, to keep him from getting any closer than he already was. |
Ahhhh gotcha! Yes I re-read your post, and (kinda) get what you're talking about. I'll have a read of the "trigger_push" code.
scar3crow wrote: | Or you could just be significantly hacky and give the chaplain the collision hull of a shambler, so he couldn't fit through doors, and would be easier to hit... ...and thus it wouldn't really be worth now that I type it out so hey =) |
Yea, I'd like his 'damagable area' to remain the same.
Q1: Out of curiosity, what was your strategy for coming up with this proposed solution? How did you know about the trigger_push code? Are you 'guessing', or have you programmed something similar? How much of the code have you actually memorized?
Q2: Is this considered 'hard'? If so, what specifically makes it a hard mod to do?
thanks,
OneManClan |
|
Back to top |
|
 |
MauveBib

Joined: 04 Nov 2004 Posts: 602
|
Posted: Sun Apr 26, 2009 6:22 pm Post subject: |
|
|
The easiest option would be to do a findradius every turn, and alter the velocity of the nearby players to push them away from him, pushing quicker if they're closer to him (i.e. if they're moving quickly relative to each other). Essentially he will have a short range "magnetic repulsion" to players on the other team. The chaplain is also pushed away slightly, but much less than the other guy for the "push up against walls bubble" to be maintained.
Something like this:
Code: |
void() chaplain_pushplayers =
{
local entity guy;
local vector direc;
local float dist;
guy = findradius(self.origin, 100);
while(guy)
{
if ((guy.flags & FL_CLIENT) && (guy.team != self.team))
{
if (vlen(guy.origin - self.origin) < 100)
{
direc = normalize(guy.origin - self.origin);
dist = (100 - (vlen(guy.origin - self.origin)));
guy.velocity = guy.velocity + direc * (dist * 3);
self.velocity = self.velocity - direc * dist;
}
}
guy = guy.chain;
}
};
|
btw this could be an excellent use for EF_BRIGHTFIELD, the swirly particle sphere id left in the code but never used. Or did they remove it from the QW code?
EDIT: Here's a video of this in action. This the sort of thing you were after? The forcefield is slightly "bouncy" rather than completely solid, much like repelling magnets.
http://elf.planetquake.gamespy.com/force.avi _________________ Apathy Now!
Last edited by MauveBib on Sun Apr 26, 2009 7:12 pm; edited 1 time in total |
|
Back to top |
|
 |
scar3crow Inside3D Staff

Joined: 18 Jan 2005 Posts: 837 Location: Las Vegas, NV
|
Posted: Sun Apr 26, 2009 7:07 pm Post subject: |
|
|
I think EF_BRIGHTFIELD is still in QW... but I'm not sure myself.
Listen to what MauveBib said, he can actually code.
Regarding trigger_push, I just thought of an instance where the player was moved without their own input based upon a radius, and that came to mind, the player enters the radius of the trigger_push brush, and is then thrust in a direction with a speed, so it seemed like a good place to start. _________________ ...and all around me was the chaos of battle and the reek of running blood.... and for the first time in my life I knew true happiness. |
|
Back to top |
|
 |
Spike
Joined: 05 Nov 2004 Posts: 944 Location: UK
|
Posted: Sun Apr 26, 2009 10:24 pm Post subject: |
|
|
you could spawn a bbox around the player, owned by the player, that is simply solid to other players. Of course, this would stop other players just as much.
Change the player's .maxspeed inside prethink based on their angles? Then they can rocketjump towards, but not run. _________________ What's a signature? |
|
Back to top |
|
 |
OneManClan
Joined: 28 Feb 2009 Posts: 62
|
Posted: Mon Apr 27, 2009 2:48 pm Post subject: |
|
|
MauveBib wrote: | EDIT: Here's a video of this in action. This the sort of thing you were after? |
MauveBib, the reason I haven't responded all day because I'm still GOBSMACKED!! And that's the first time I've EVER used the expression 'GOBSMACKED' ! I still don't know what to say..... Um .. er ..YES, that EXACTLY the sort of thing I was after. Utterly Brilliant!!!
But... how MauveBob? Did you just think that off the top of your head?!!?!?!! Wow.
MauveBib wrote: | The forcefield is slightly "bouncy" rather than completely solid, much like repelling magnets. |
Perfect. Ever better than I imagined it. The bounce makes the field seem more 'alive'. I mean it's supposed to be an 'energy field', and not a solid object anyway. Having said that, can the speed ('hardness'?) of the 'bounce' be adjusted? In the vid it looks like the players can actually touch each other.
Btw, I installed the code into CustomTF, and the 'bounciness' was even softer. I mean like every 1 second there was a weak 'gentle pulse', slowly nudging the enemy away. I easily got close enough to kill the chap w an axe. Your vid looks much faster, so I assume I'm missing something. I increased the radius (I changed every occurrence of '100' to '300'), but it made no difference to the 'power of the push', only that the final position was further.
Realising that making suggestions to you is like performing 'chopsticks' for Mozart, what if there WAS an inner 'solid' region (radius 100?), surrounded by the bouncier outer shell(radius 200?). Ideally, when chapping, I'd like it so that you can walk right into a bunch of enemies without breaking your stride, and no-one able to touch you.
I couldn't see any way to increase the 'hardness' of the 'bounce'.
MauveBib wrote: | btw this could be an excellent use for EF_BRIGHTFIELD, the swirly particle sphere id left in the code but never used. Or did they remove it from the QW code? |
Well, I replaced the two occurrences of EF_BRIGHTLIGHT with EF_BRIGHTFIELD:
Code: | //self.effects = self.effects | #EF_BRIGHTLIGHT;
self.effects = self.effects | #EF_BRIGHTFIELD;
|
tried it, it compiled, but I didn't see ANY effect whilst running it in EZquake. It IS defined in defs.qc:
Code: | // entity effects
#define EF_BRIGHTFIELD 1
|
OneManClan
Last edited by OneManClan on Mon Apr 27, 2009 4:11 pm; edited 2 times in total |
|
Back to top |
|
 |
Spike
Joined: 05 Nov 2004 Posts: 944 Location: UK
|
Posted: Mon Apr 27, 2009 2:54 pm Post subject: |
|
|
EF_BRIGHTFIELD is not supported in quakeworld. _________________ What's a signature? |
|
Back to top |
|
 |
MauveBib

Joined: 04 Nov 2004 Posts: 602
|
Posted: Mon Apr 27, 2009 3:50 pm Post subject: |
|
|
OneManClan wrote: |
But... how MauveBob? Did you just think that off the top of your head?!!?!?!! Wow.
|
I've been coding QC for 10 years, it comes pretty easily after a while.
OneManClan wrote: |
Having said that, can the speed ('hardness'?) of the 'bounce' be adjusted? In the vid it looks like the players can actually touch each other.
|
Yes, it's adjustable, though they can't quite touch each other, as the power of the "push" becomes stronger as they get closer.
Code: |
guy.velocity = guy.velocity + direc * (dist * 3);
self.velocity = self.velocity - direc * dist;
|
These are the two lines that define the strength of the push. The first line is the strength of the push on the other guy, the second is the strength of the push on the chaplain. Currently the strength is 3 times the inverse distance on the other guy, and just the inverse distance on the chaplain; increase this to 5x and 2x or something to make it more powerful. Something like this:
Code: |
guy.velocity = guy.velocity + direc * (dist * 5);
self.velocity = self.velocity - direc * (dist * 2);
|
As for the problem of only pushing once a second or so, I'd say the problem is where you are calling the function from. This function needs to be run every frame in order to get the effect as shown in the video. If you're calling it less often than that you'll get the "shunting" effect you describe.
Spike wrote: | EF_BRIGHTFIELD is not supported in quakeworld. |
Well, that throws that idea out then Hmm, it's tricky to do a cool forcefield effect without transparency or anything, but I'll have a think about it. _________________ Apathy Now! |
|
Back to top |
|
 |
FrikaC Site Admin

Joined: 08 Oct 2004 Posts: 947
|
Posted: Mon Apr 27, 2009 7:13 pm Post subject: |
|
|
Were those actual clients in your vid? It's odd to see Unnamed changed name to X messages for bots, unless you're using the DP botclient stuff, which I've never messed around with. |
|
Back to top |
|
 |
MauveBib

Joined: 04 Nov 2004 Posts: 602
|
Posted: Mon Apr 27, 2009 9:27 pm Post subject: |
|
|
FrikaC wrote: | Were those actual clients in your vid? It's odd to see Unnamed changed name to X messages for bots, unless you're using the DP botclient stuff, which I've never messed around with. |
They were DP botclients. _________________ Apathy Now! |
|
Back to top |
|
 |
FrikaC Site Admin

Joined: 08 Oct 2004 Posts: 947
|
Posted: Mon Apr 27, 2009 10:19 pm Post subject: |
|
|
cool beans. |
|
Back to top |
|
 |
Electro
Joined: 29 Dec 2004 Posts: 241 Location: Brisbane, Australia
|
Posted: Tue Apr 28, 2009 5:32 am Post subject: |
|
|
Yeah DP has that problem with connecting botclients. I mentioned it a while ago but I guess it's still there. _________________ Unit reporting!
http://www.bendarling.net/ |
|
Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2004 phpBB Group
|