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

Send Ent to Origin with Gravity


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
madeitout
Member
Join Date: Jun 2008
Old 07-22-2009 , 05:07   Send Ent to Origin with Gravity
Reply With Quote #1

I have an entitiy that I want to fly and hit an exact origin. I have a function that will do it but the function doesn't account for gravity and assumes the entities movetype is fly but I need it to calculate the velocities with gravity included.

here is the function

PHP Code:
stock send_to_origin(enttarget_origin[3], Float:speed)
{
    if (!
pev_valid(ent))
        return 
0;

    new 
Float:entity_origin[3];
    
pev(entpev_originentity_origin);

    new 
Float:diff[3];
    
diff[0] = target_origin[0] - entity_origin[0];
    
diff[1] = target_origin[1] - entity_origin[1];
    
diff[2] = target_origin[2] - entity_origin[2];

    new 
Float:length floatsqroot(floatpower(diff[0], 2.0) + floatpower(diff[1], 2.0) + floatpower(diff[2], 2.0));

    new 
Float:velocity[3];
    
velocity[0] = diff[0] * (speed length);
    
velocity[1] = diff[1] * (speed length);
    
velocity[2] = diff[2] * (speed length);
    
set_pev(entpev_velocityvelocity);

    return 
1;

any help is appreciated, thank you
madeitout is offline
xbatista
Veteran Member
Join Date: Mar 2008
Location: Lithuania
Old 07-22-2009 , 05:14   Re: Send Ent to Origin With Gravity
Reply With Quote #2

Show us your code where you creating entity ?
__________________
xbatista is offline
Send a message via Skype™ to xbatista
madeitout
Member
Join Date: Jun 2008
Old 07-22-2009 , 05:23   Re: Send Ent to Origin With Gravity
Reply With Quote #3

oh sorry here you are
PHP Code:
public make_nade(id)
{
    new 
Float:angles[3], Float:origin[3], ent engfunc(EngFunc_CreateNamedEntityengfunc(EngFunc_AllocString"info_target"));
    if (
pev_valid(ent) && is_user_alive(id))
    {
        
set_pev(entpev_classname"grenade");
        
set_pev(entpev_ownerid);
        
set_pev(entpev_solid2);
        
set_pev(entpev_movetype6);
        
set_pev(entpev_gravity1.0);
        
engfunc(EngFunc_SetModelent"models/grenade.mdl");
        
engfunc(EngFunc_SetSizeentFloat:{-6.0, -6.0, -6.0}, Float:{6.06.06.0});

        
pev(idpev_v_angleangles);
        
set_pev(entpev_anglesangles);
        
pev(idpev_originorigin);
        
engfunc(EngFunc_SetOriginentorigin);

        return 
ent;
    }
    return 
0;

madeitout is offline
xbatista
Veteran Member
Join Date: Mar 2008
Location: Lithuania
Old 07-22-2009 , 05:34   Re: Send Ent to Origin With Gravity
Reply With Quote #4

Take a look of my rpg code :
PHP Code:
// RPG Launcher Stuff
public act_launch(id)
{    
    new 
rocket_ent create_entity("info_target");
    
    if (!
pev_valid(rocket_ent) || !is_user_alive(id) )
        return;
    
    
set_pev(rocket_ent ,pev_classname"RPG")
    
engfunc(EngFunc_SetModelrocket_entg_w_rpg)
    
    
set_pevrocket_entpev_ownerid)
    
set_pevrocket_entpev_movetypeMOVETYPE_FLY)
    
set_pevrocket_entpev_solidSOLID_BBOX)
    
    
set_pevrocket_entpev_minsFloat:{-1.0,-1.0,-1.0})
    
set_pevrocket_entpev_maxsFloat:{1.0,1.0,1.0})
    
    new 
Float:fAim[3],Float:fAngles[3],Float:fOrigin[3]
    
    
pev(id,pev_origin,fOrigin)
    
velocity_by_aim(id,64,fAim)
    
vector_to_angle(fAim,fAngles)

    
    
fOrigin[0] += fAim[0]
    
fOrigin[1] += fAim[1]
    
fOrigin[2] += fAim[2]
    
    
set_pev(rocket_ent,pev_origin,fOrigin)
    
set_pev(rocket_ent,pev_angles,fAngles)
    
    new 
Float:fVel[3]
    
velocity_by_aim(id1500,fVel)    
    
set_pev(rocket_ent,pev_velocity,fVel)

Sorry I'm little lazy now to explain, must go
__________________

Last edited by xbatista; 07-22-2009 at 05:39.
xbatista is offline
Send a message via Skype™ to xbatista
madeitout
Member
Join Date: Jun 2008
Old 07-22-2009 , 06:20   Re: Send Ent to Origin With Gravity
Reply With Quote #5

thanks man but that code basically does the exact thing as what the stock that i have does. Both of our codes only calculate a velocity that will hit the target if the entity has no gravity (MOVETYPE_FLY).

im not very good at angle math and such so what i need is someone math wiz to edit my formula so it accounts for gravity because my ent is MOVETYPE_TOSS, thanks thou
madeitout is offline
xbatista
Veteran Member
Join Date: Mar 2008
Location: Lithuania
Old 07-22-2009 , 06:25   Re: Send Ent to Origin With Gravity
Reply With Quote #6

You mean throw entity like a grenade (gravity) ?
__________________
xbatista is offline
Send a message via Skype™ to xbatista
madeitout
Member
Join Date: Jun 2008
Old 07-22-2009 , 06:30   Re: Send Ent to Origin With Gravity
Reply With Quote #7

yea the rpg you made has the movetype set to fly so it has no gravity and will just float so it you set its velocity to like 1 it will just slowly float ahead until its hits something, but the grenade that i made has a movetype of toss which means it has gravity. If you set its velocity to 1 its will move forward and then gravity will pull it to the ground like a normal nade.

If I use either of our formulas on my grenade it will start off towards the target origin but the gravity will grab it and pull it down before it gets to the target
madeitout is offline
Alka
AMX Mod X Plugin Approver
Join Date: Dec 2006
Location: malloc(null)
Old 07-22-2009 , 06:31   Re: Send Ent to Origin With Gravity
Reply With Quote #8

Creating a ent with movetype MOVETYPE_TOSS and setting pev_gravity should do the job.

Quote:
Originally Posted by madeitout View Post
If I use either of our formulas on my grenade it will start off towards the target origin but the gravity will grab it and pull it down before it gets to the target
Set the gravity to a lower value...
__________________
Still...lovin' . Connor noob! Hello
Alka is offline
xbatista
Veteran Member
Join Date: Mar 2008
Location: Lithuania
Old 07-22-2009 , 06:33   Re: Send Ent to Origin With Gravity
Reply With Quote #9

PHP Code:
    set_pev(entpev_gravity1.3);
    
set_pev(entpev_friction1.0); 
__________________
xbatista is offline
Send a message via Skype™ to xbatista
madeitout
Member
Join Date: Jun 2008
Old 07-22-2009 , 06:45   Re: Send Ent to Origin With Gravity
Reply With Quote #10

thanks guys but my ent is already set to toss and in order to get the entity to hit the exact origin by moding the gravity, I would need to find the exact gravity for my ent which im unsure how to calc and it would also make the ent appear slower and float more ingame. I perfer to just modify my formula so the ent gets more velocity from the start and will hit the target. Ill wait a day or two and then I might need to go to a math forum and see if they can make me a forumla that will do it more me.
madeitout 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 08:34.


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