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

Circular motion


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Grzyboo
Junior Member
Join Date: Apr 2011
Old 12-25-2013 , 07:50   Circular motion
Reply With Quote #1

Hello, i need to make kind of circular motion. I just want to keep the distance between 2 entities and change one's origins. I have no idea how to do such thing.

Are there any functions that could help?
It should be something like this:

PHP Code:
new const Float:fDistance 500.0;
new 
Float:Origin1[3], Float:Origin2[3], Float:Origin3[3];

entity_get_vector(ent1EV_VEC_originOrigin1);
entity_get_vector(ent2EV_VEC_originOrigin2);

/*
Get a line passing both Origin1 and Origin2
Rotate line (sth like 15 degrees for example)
Place Origin3 on that line, in specified distance (fDistance)
*/ 
If anyone has concept how to do anything from this, I'd be pleased to hear your ideas.
I attach a crazy painting

Last edited by Grzyboo; 12-25-2013 at 07:51.
Grzyboo is offline
Pastout
Senior Member
Join Date: Dec 2010
Location: 1337 Street LeetTown
Old 12-25-2013 , 08:16   Re: Circular motion
Reply With Quote #2

Not really sure what you're trying to do but... The way this function work's is it grabs the positions of 3 players and uses the law of cosines to find the angle of B.
PHP Code:
stock Float:getPlayersAngle_BplayerAplayerBplayerC ) {
        
// 1. Grab position of all players (ignore Z positions)
        
new Float:vecOriginA], Float:vecOriginB],
                
Float:vecOriginC]
        
        
entity_get_vectorplayerAEV_VEC_originvecOriginA )
        
entity_get_vectorplayerBEV_VEC_originvecOriginB )
        
entity_get_vectorplayerCEV_VEC_originvecOriginC )
        
        
vecOriginA] = vecOriginB] = vecOriginC] = 0.0
        
        
// 2. Grab the line vectors for all sides
        
new Float:vecLineAB], Float:vecLineBC],
                
Float:vecLineAC]
        
        
xs_vec_subvecOriginAvecOriginBvecLineAB )
        
xs_vec_subvecOriginBvecOriginCvecLineBC )
        
xs_vec_subvecOriginAvecOriginCvecLineAC )
        
        
// 3. Grab the length of each side we'll need
        
new Float:flLineAB vector_lengthvecLineAB ), Float:flLineBC vector_lengthvecLineBC ),
                
Float:flLineAC vector_lengthvecLineAC )
        
// 4. Use the law of cosines to find the angle of B
        
        // cos B = (AB^2 + BC^2 - AC^2) / 2(AB)(BC)
        // B = acos (AB^2 + BC^2 - AC^2) / 2(AB)(BC)
        
return floatacos( ( flLineAB flLineAB flLineBC flLineBC flLineAC flLineAC ) / ( flLineAB flLineBC ), degrees )

Pastout 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 18:09.


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