AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Calculating circular origin? (https://forums.alliedmods.net/showthread.php?t=337811)

AdrenalinesWrath 05-16-2022 18:56

Calculating circular origin?
 
hello everyone,

I'm trying to get origins around an origin to create a beam between center and the end of the circle
and I'm not really good at math lol.
for example origin would be {0.0,0.0,0.0} which would be the center, and the distance would be 150.0

so I want to make it start from the top of it, and make it go in circular motion by 360°

any snippet for it?

probably by using floatsin() and floatcos()? I have no idea how to use them

thanks in advance!


Figured it out! here's a lil snippet if anyone needs it:
PHP Code:

stock get_circular_origin(Float:angleFloat:origin[3], Float:radius,Float:COrigin[3])
{
       
COrigin[0] = radius floatcos(angle,degrees);
       
COrigin[1] = origin[1]
       
COrigin[2] = radius floatsin(angle,degrees);



XSlayer 05-17-2022 03:56

Re: Calculating circular origin?
 
Quote:

Originally Posted by AdrenalinesWrath (Post 2779578)
hello everyone,

I'm trying to get origins around an origin to create a beam between center and the end of the circle
and I'm not really good at math lol.
for example origin would be {0.0,0.0,0.0} which would be the center, and the distance would be 150.0

so I want to make it start from the top of it, and make it go in circular motion by 360°

any snippet for it?

probably by using floatsin() and floatcos()? I have no idea how to use them

thanks in advance!


Figured it out! here's a lil snippet if anyone needs it:
PHP Code:

stock get_circular_origin(Float:angleFloat:origin[3], Float:radius,Float:COrigin[3])
{
       
COrigin[0] = radius floatcos(angle,degrees);
       
COrigin[1] = origin[1]
       
COrigin[2] = radius floatsin(angle,degrees);



This Can Help u

PHP Code:

new Float:g_vec[3] = {25.00.0, -20.0}
new 
Float:g_deg 0;

public 
fxWindFXClient )
{    
       
set_task(0.05"rotate"Client__"b"1);
 
       
set_task(1.0"fxRestore"Client__"b"1);
}
public 
fxRestoreClient )
{
        
g_vec[0] = 25.0;
        
g_vec[1] = 0.0;
        
g_vec[2] = -20.0;
}
public 
rotate(Client)
{
    new 
Float:xFloat:y
    x 
25*floatcos(g_degdegrees);
    
25*floatsin(g_degdegrees);
    
g_deg += 70;
    
    
display(Client)
    
    
g_vec[0] = x
    g_vec
[1] = y
    g_vec
[2] += 8.0;
}
public 
display(Client)
{
        new 
origin[3];

        
get_user_origin(Clientorigin)

        
message_begin(MSG_PVSSVC_TEMPENTITYorigin)
        
write_byte(TE_SPRITE// TE id
        
write_coord(floatround(g_vec[0] + origin[0]) )
        
write_coord(floatround(g_vec[1] + origin[1]) )
        
write_coord(floatround(g_vec[2] + origin[2]) )
        
write_shortengfuncEngFunc_ModelIndex"sprites/steam1.spr") );
        
write_byte(3// scale
        
write_byte(255// framerate
        
message_end() 



Natsheh 05-17-2022 08:16

Re: Calculating circular origin?
 
https://forums.alliedmods.net/showthread.php?t=336136

Use find_location_around_origin in the first post.

XSlayer 05-17-2022 18:55

Re: Calculating circular origin?
 
Quote:

Originally Posted by Natsheh (Post 2779605)
https://forums.alliedmods.net/showthread.php?t=336136

Use find_location_around_origin in the first post.

totally unnecessary and poorly optimized for what he needs.

Natsheh 05-18-2022 06:17

Re: Calculating circular origin?
 
Quote:

Originally Posted by XSlayer (Post 2779643)
totally unnecessary and poorly optimized for what he needs.

He didn't explain properly and its not poorly optimized, rather more competent, that isnt the thing he needed.

and FFS don't use grey color as the font color it makes it difficult to be read.

AdrenalinesWrath 05-20-2022 08:39

Re: Calculating circular origin?
 
sorry for the late response everyone, thank you @XSlayer and @Natsheh for the help!

I used gray color cause I meant to show that I solved the problem.
what I was trying to do is create an entity that would rotate horizontally or vertically around the player and keeping it at the same direction even if the player turns around.

I ended up with these lines which did what I needed:

PHP Code:

static Float:VicOrigin[3], Float:EntOrigin[3]

    
pev(entpev_originEntOrigin)
    
pev(victimpev_originVicOrigin)
    
VicOrigin[0] = VicOrigin[0]+(200.0 floatcos(ang,degrees));
    
VicOrigin[2] = VicOrigin[2]+(200.0 floatsin(ang,degrees));
    
set_pev(ent,pev_origin,VicOrigin); 

and I used pev_origin for a reason instead of pev_velocity


All times are GMT -4. The time now is 21:23.

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