Raised This Month: $51 Target: $400
 12% 

Push player away from center


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Mr. Zero
Veteran Member
Join Date: Jun 2009
Location: Denmark
Old 10-16-2011 , 14:23   Push player away from center
Reply With Quote #1

Never really been good with all this vector stuff.

I simply want to specify 1 point and then keep all players outside in a certain radius.
Kinda like a force field. When a player gets closer to the point, the stronger the backwards push will be, keeping the player out.

PHP Code:
static PushPlayersAwayFromPoint(const Float:origin[3], const Float:radius)
{
    
decl Float:playerOrigin[3];
    
decl Float:playerVelocity[3];
    
decl Float:resultVel[3];

    for (new 
client 1client <= MaxClientsclient++)
    {
        if (!
IsClientInGame(client) || !IsPlayerAlive(client)) continue;

        
GetClientAbsOrigin(clientplayerOrigin);
        if (
GetVectorDistance(originplayerOrigin) > radius) continue;

        
GetEntPropVector(clientProp_Data"m_vecVelocity"playerVelocity);

        
// Insert math done to resultVel in order to push the player away from origin

        
TeleportEntity(clientNULL_VECTORNULL_VECTORresultVel);
    }

Mr. Zero is offline
blodia
Veteran Member
Join Date: Sep 2009
Location: UK
Old 10-16-2011 , 16:31   Re: Push player away from center
Reply With Quote #2

point_push. you can use a negative magnitude to makes a blackhole.
blodia is offline
pheadxdll
AlliedModders Donor
Join Date: Jun 2008
Old 10-16-2011 , 16:39   Re: Push player away from center
Reply With Quote #3

You just want to inverse their velocity, but point_push is a good idea.
__________________
pheadxdll is offline
Mr. Zero
Veteran Member
Join Date: Jun 2009
Location: Denmark
Old 10-17-2011 , 08:10   Re: Push player away from center
Reply With Quote #4

How would I go about to inverse the vectors?
Mr. Zero is offline
Scone
Senior Member
Join Date: Apr 2010
Location: England
Old 10-17-2011 , 09:51   Re: Push player away from center
Reply With Quote #5

To invert a vector you just negate all of the components (i.e. v[0] = -v[0], etc). You can use the NegateVector function to do this automatically.
__________________
Scone is offline
Monkeys
Veteran Member
Join Date: Jan 2010
Old 10-17-2011 , 14:33   Re: Push player away from center
Reply With Quote #6

Inversing their velocity would only work if the position you're trying to push from is a line.
If it were a point, you'd also get pushed backwards in a straight line if you were to walk next to the point, but in range.
(As shown in my horrible attempt at ascii drawing)
Quote:
Initial movement & Changed velocity

<-----X ---->
O This is the point you're supposed to be pushing away from
__________________
Get a lid on that zombie,
he's never gonna be alri-i-ight.
Oooh get a lid on that zombie,
or he's gonna feed all night.
Monkeys is offline
FoxMulder
Senior Member
Join Date: Jan 2009
Location: Orlando, FL
Old 10-20-2011 , 09:44   Re: Push player away from center
Reply With Quote #7

This is some unused code I have laying around. I forgot if it worked or not but it looks like I was attaching the point_push to an object. I'm pretty sure it worked cause I remember everyone complaining about their movement being restricted


All you need to do to use this function is pass the entity you want to attach it to along with their targetname.

PHP Code:

public attachPoint_Push(entFloat:zOffsetString:parentName[])
{
    new 
point_push CreateEntityByName("point_push");

    if (
IsValidEdict(point_push))
    {
        new 
Float:pos[3]; 
        
GetEntPropVector(entProp_Send"m_vecOrigin"pos);
        
pos[2] += zOffset;
        
        
        
        
DispatchKeyValue(point_push"targetname""tf2particle");
        
DispatchKeyValue(point_push"parentname"parentName);
        
        
///VALUES
        
DispatchKeyValue(point_push"enabled""1");
        
DispatchKeyValue(point_push"magnitude""1000.0");
        
DispatchKeyValue(point_push"radius""200.0");
        
DispatchKeyValue(point_push"inner_radius""200.0");
        
DispatchKeyValue(point_push"spawnflags""8");
        
        
DispatchSpawn(point_push);
        
        new 
iTeam =  GetEntProp(entProp_Data"m_iTeamNum");
        
SetVariantInt(iTeam);
        
AcceptEntityInput(point_push"TeamNum", -1, -10);
        
        
SetVariantInt(iTeam);
        
AcceptEntityInput(point_push"SetTeam", -1, -10);
        
        
SetVariantString(parentName);
        
AcceptEntityInput(point_push"SetParent"point_pushpoint_push0);
        
        
ActivateEntity(point_push);
        
AcceptEntityInput(point_push"TurnOn");
        
        
ActivateEntity(point_push);
        
AcceptEntityInput(point_push"Enable");
        
        
TeleportEntity(point_pushposNULL_VECTORNULL_VECTOR);
    }

__________________

Last edited by FoxMulder; 10-20-2011 at 09:46.
FoxMulder is offline
AtomicStryker
Veteran Member
Join Date: Apr 2009
Location: Teutonia!!
Old 10-23-2011 , 06:04   Re: Push player away from center
Reply With Quote #8

Use MakeVectorFromPoints from your 'force' to the player, and then adjust it's lenght (multiply all values by the same factor) to determine strength. Then apply as velocity.
AtomicStryker is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 22:10.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode