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

Create random velocity


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
bibu
Veteran Member
Join Date: Sep 2010
Old 03-15-2014 , 06:24   Create random velocity
Reply With Quote #1

I would like to create an entity and then effect a random way of pushing it away. I know some calculation with the xs functions should be used and since I don't have also much knownledge with velocity and much I would like to know how todo such effect.

Attached is a picture what I would like to achieve.

__________________
Selling tons of my own private works.
Accepting paid work for clans and communities.
Don't hesitate to contact me.
bibu is offline
Kiske
Veteran Member
Join Date: May 2009
Old 03-15-2014 , 11:01   Re: Create random velocity
Reply With Quote #2

I think the code belongs to Connor or Exolent or xPaw, I don't know, I try to find the post.


PHP Code:
// In plugin_init()
g_MaxPlayers get_maxplayers();

new const 
Float:MAX_DISTANCE 215.0;
new const 
PUSH_FORCE = -65;

// In your code:
new Float:vecEntOrigin[3];
new 
Float:vecVictimorigin[3];
new 
Float:fDistance;
new 
i;

entity_get_vector(iEntEV_VEC_originvecEntOrigin);

for(
1<= g_MaxPlayers; ++i) { 
    if(
is_user_alive(i)) {
        
entity_get_vector(iEV_VEC_originvecVictimorigin);
        
        
fDistance get_distance_f(vecEntOriginvecVictimorigin);
        
        if(
fDistance >= MAX_DISTANCE)
            continue;
        
        
xs_vec_sub(vecVictimoriginvecEntOriginvecVictimorigin);
        
xs_vec_normalize(vecVictimoriginvecVictimorigin)
        
xs_vec_mul_scalar(vecVictimorigin, (MAX_DISTANCE MAX_DISTANCE) * PUSH_FORCEvecVictimorigin)
        
        
entity_set_vector(iEV_VEC_velocityvecVictimorigin);
    }


Or try this: https://forums.alliedmods.net/showpo...0&postcount=13
__________________


Last edited by Kiske; 03-15-2014 at 11:06.
Kiske is offline
Send a message via Skype™ to Kiske
bibu
Veteran Member
Join Date: Sep 2010
Old 03-15-2014 , 11:54   Re: Create random velocity
Reply With Quote #3

Since the origin of the ent is the same and I would like to have this completely random, that doesn't really help me.
__________________
Selling tons of my own private works.
Accepting paid work for clans and communities.
Don't hesitate to contact me.
bibu is offline
Kiske
Veteran Member
Join Date: May 2009
Old 03-15-2014 , 12:32   Re: Create random velocity
Reply With Quote #4

Quote:
Originally Posted by bibu View Post
Since the origin of the ent is the same and I would like to have this completely random, that doesn't really help me.
I don't understand.
If the entity moves, use set_task or a think.
__________________


Last edited by Kiske; 03-15-2014 at 12:34.
Kiske is offline
Send a message via Skype™ to Kiske
micapat
Veteran Member
Join Date: Feb 2010
Location: Nyuu, nyuu (France).
Old 03-15-2014 , 13:11   Re: Create random velocity
Reply With Quote #5

PHP Code:
new FloatvVelocity];

vVelocity] = random_float( -300.0300.0 );
vVelocity] = random_float( -300.0300.0 );
vVelocity] = random_float( -300.0300.0 );

set_peviEntitypev_velocityvVelocity ); 
__________________
micapat is offline
bibu
Veteran Member
Join Date: Sep 2010
Old 03-16-2014 , 11:38   Re: Create random velocity
Reply With Quote #6

Quote:
Originally Posted by micapat View Post
PHP Code:
new FloatvVelocity];

vVelocity] = random_float( -300.0300.0 );
vVelocity] = random_float( -300.0300.0 );
vVelocity] = random_float( -300.0300.0 );

set_peviEntitypev_velocityvVelocity ); 
Wow setting actually velocity does do the job, thank you very much.

In case someone can't get it to run, you also gotta set the move type of the entity to bounce.
__________________
Selling tons of my own private works.
Accepting paid work for clans and communities.
Don't hesitate to contact me.
bibu 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 11:10.


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