Raised This Month: $ Target: $400
 0% 

Calculate velocity to point X


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 03-24-2020 , 18:22   Calculate velocity to point X
Reply With Quote #1

Hi,

So I'm looking for a way to calculate how much velocity it would require to give to the entity, to reach point X (whereas point X is player aiming origin).
I'm using velocity_by_aim and MOVETYPE_TOSS (MOVETYPE_TOSS so gravity can pull the entity down, making it more realistic).

An example in real life:
Calculating how much force it would require to throw a rock so the rock can fall on point X.
__________________

Last edited by edon1337; 03-24-2020 at 18:22.
edon1337 is offline
Send a message via Skype™ to edon1337
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 03-25-2020 , 04:02   Re: Calculate velocity to point X
Reply With Quote #2

destOrigin - sourceOrigin + normalize + multiply by speed.

P.S: force and velocity are 2 different things.
__________________

Last edited by HamletEagle; 03-25-2020 at 04:04.
HamletEagle is offline
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 03-27-2020 , 11:57   Re: Calculate velocity to point X
Reply With Quote #3

Quote:
Originally Posted by HamletEagle View Post
force and velocity are 2 different things.
You apply force to an object, it's velocity changes, I'm aware, but in CS you can't apply force to objects, you can only change their velocity. Thanks for the answer, I'll try it.
__________________

Last edited by edon1337; 03-27-2020 at 11:57.
edon1337 is offline
Send a message via Skype™ to edon1337
LostMind
New Member
Join Date: Mar 2020
Old 04-05-2020 , 10:41   Re: Calculate velocity to point X
Reply With Quote #4

Quote:
Originally Posted by HamletEagle View Post
destOrigin - sourceOrigin + normalize + multiply by speed.

P.S: force and velocity are 2 different things.
Hi, so i wanted to say that i requested doni to post this for me and maybe i would get some help.
But we didn't solve this problem.
Code:
					new Float:fPlayerOrigin[3], iAimOrigin[3], Float:fAngle[ 3 ];
					get_user_origin( id, iAimOrigin, 3 );
					
					pev( id, pev_origin, fPlayerOrigin );
					pev( id, pev_angles, fAngle );
					
					new iEnt = create_entity( "info_target" );
					
					entity_set_string( iEnt, EV_SZ_classname, "_entity" );
					entity_set_model( iEnt, spit_model );
					entity_set_size( iEnt, Float:{ -1.5, -1.5, -1.5 }, Float:{ 1.5, 1.5, 1.5 } );
					entity_set_origin( iEnt, fPlayerOrigin );
					entity_set_vector( iEnt, EV_VEC_angles, fAngle );
					entity_set_int( iEnt, EV_INT_solid, 2 );
					entity_set_int( iEnt, EV_INT_rendermode, 5 );
					entity_set_float( iEnt, EV_FL_renderamt, 200.0 );
					entity_set_float( iEnt, EV_FL_scale, 1.00 );
					entity_set_int( iEnt, EV_INT_movetype, MOVETYPE_TOSS );
					entity_set_float(iEnt, EV_FL_gravity, 1.0)
					entity_set_edict( iEnt, EV_ENT_owner, id );
					
					iAimOrigin[ 0 ] -= fPlayerOrigin[ 0 ];
					iAimOrigin[ 1 ] -= fPlayerOrigin[ 1 ];
					iAimOrigin[ 2 ] -= fPlayerOrigin[ 2 ];
					
					new Float:fNormalizedVec[ 3 ], Float:fFinalVec[ 3 ];
					xs_vec_normalize( Float:iAimOrigin, fNormalizedVec );
					xs_vec_mul_scalar( fNormalizedVec, float(pev( iEnt, pev_maxspeed )), fFinalVec )
Here it is the code. If you have time. Can you see where is the problem? And also, the entity goes down only.

Last edited by LostMind; 04-05-2020 at 10:42.
LostMind is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 04-06-2020 , 04:11   Re: Calculate velocity to point X
Reply With Quote #5

1.Convert iAimOrigin to float using IVecFVec.
2.float(pev(lev_maxspeed)) that's not the right way to retrieve floats using pev(). Pass the float variable as the 3rd param.
__________________

Last edited by HamletEagle; 04-06-2020 at 04:12.
HamletEagle is offline
LostMind
New Member
Join Date: Mar 2020
Old 04-13-2020 , 14:07   Re: Calculate velocity to point X
Reply With Quote #6

Quote:
Originally Posted by HamletEagle View Post
1.Convert iAimOrigin to float using IVecFVec.
2.float(pev(lev_maxspeed)) that's not the right way to retrieve floats using pev(). Pass the float variable as the 3rd param.
I'm so sorry but i already tried everything i could and searched a lot. But the entity goes only down.
I don't know what's the matter.
Code:
 					new Float:fPlayerOrigin[3], Float:fAngle[3 ], iAimOrigin[3], Float:iAimOrigin1[3]
					get_user_origin(id, iAimOrigin, 3)
					IVecFVec(iAimOrigin, iAimOrigin1)
					
					entity_get_vector(id, EV_VEC_origin , fPlayerOrigin)
					entity_get_vector(id, EV_VEC_v_angle, fAngle)
					new iEnt = create_entity( "info_target" );
					
					entity_set_string( iEnt, EV_SZ_classname, "_entity" );
					entity_set_model( iEnt, spit_model );
					entity_set_size( iEnt, Float:{ -1.5, -1.5, -1.5 }, Float:{ 1.5, 1.5, 1.5 } );
					entity_set_origin( iEnt, fPlayerOrigin );
					entity_set_vector( iEnt, EV_VEC_angles, fAngle );
					entity_set_int( iEnt, EV_INT_solid, 2 );
					entity_set_int( iEnt, EV_INT_rendermode, 5 );
					entity_set_float( iEnt, EV_FL_renderamt, 200.0 );
					entity_set_float( iEnt, EV_FL_scale, 1.00 );
					entity_set_int( iEnt, EV_INT_movetype, MOVETYPE_TOSS );
					entity_set_float(iEnt, EV_FL_gravity, 1.0)
					entity_set_edict( iEnt, EV_ENT_owner, id );
					
					iAimOrigin1[ 0 ] -= fPlayerOrigin[ 0 ];
					iAimOrigin1[ 1 ] -= fPlayerOrigin[ 1 ];
					iAimOrigin1[ 2 ] -= fPlayerOrigin[ 2 ];
					
					new Float:fNormalizedVec[ 3 ], Float:fFinalVec[ 3 ]
					xs_vec_normalize( iAimOrigin1, fNormalizedVec )
					xs_vec_mul_scalar( fNormalizedVec, 10.0, fFinalVec )

Last edited by LostMind; 04-13-2020 at 14:09.
LostMind is offline
Reply


Thread Tools
Display Modes

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 10:25.


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