Raised This Month: $32 Target: $400
 8% 

Turn angle in period [SOLVED]


Post New Thread Reply   
 
Thread Tools Display Modes
aron9forever
Veteran Member
Join Date: Feb 2013
Location: Rromania
Old 09-29-2014 , 16:25   Re: Turn angle in period
Reply With Quote #11

Quote:
Originally Posted by usaexelent View Post
Common guys, please help me
Well pardon you but I think I'm pretty unique in my way OKAY?
__________________
Meanwhile, in 2050:
Quote:
Originally Posted by aron9forever
useless small optimizations
Quote:
Originally Posted by Black Rose View Post
On a map that is 512x512x128 units you end up with 3,355,443,200,000 different "positions". To store each one of those positions individually in the variable "user_or" you need 12 terabytes of memory.
aron9forever is offline
GordonFreeman (RU)
Veteran Member
Join Date: Jan 2010
Location: Uzbekistan
Old 09-29-2014 , 21:56   Re: Turn angle in period
Reply With Quote #12

For entity you can use EV_VEC_avelocity.
Code:
entity_set_vector(ent,EV_VEC_avelocity,Float:{0.0,50.0,0.0})
Don't forget to check that entity don't block on collide.
__________________
The functional way is the right way

Last edited by GordonFreeman (RU); 09-29-2014 at 21:56.
GordonFreeman (RU) is offline
usaexelent
Senior Member
Join Date: Nov 2009
Location: Lithuania
Old 10-01-2014 , 12:26   Re: Turn angle in period
Reply With Quote #13

This doesn't change anything, there's something bad in turning function, that's why it only turns in one direction. I need someone to help me who's expert in angles or at least understands what this is all about.

No offense GordonFreeman (RU) and aron9forever.
__________________
and once again

Last edited by usaexelent; 10-01-2014 at 12:27.
usaexelent is offline
Send a message via Skype™ to usaexelent
.Dare Devil.
Veteran Member
Join Date: Sep 2010
Old 10-02-2014 , 01:28   Re: Turn angle in period
Reply With Quote #14

Your problem appears when ideal and angle difference is more than 180.0
PHP Code:
ideal[a] - angles[a
if it is however more than 180 it would mean:
ideal: 320
angle: 30
without using the function below it would go 320 > 30 but we need to go the other way
and to do that we need to do ideal - 360 so ideal will be -40 what is same like 320.
now when we get the difference
ideal:-40 - angle: 30 = 70
as you can see its smaller now and it will go to the right way, the closest way...

PHP Code:
stock fix_idealFloat:angles[3], Float:ideal[3] ) 

    new 
Float:d
    
for( 03a++ ) 
    { 
        
ideal[a] - angles[a
        if( 
>= 180.0 ideal[a] -= 360.0
        
if( <= -180.0 ideal[a] += 360.0
    


this should definitely work ... not sure what i created last time hahaha
I guess sometimes i have those time when writing stuff down from my mind is quite hard.

PS: use the function each time you update ideal and need to update angles with my func.
Don't convert angles to the ranges 0.0 > < 360.0, that would mess things up.

You must hold ideal angles on variable, not in pev_angles since it will convert angles to that range as i remembered correctly

Last edited by .Dare Devil.; 10-02-2014 at 01:28.
.Dare Devil. is offline
Sylwester
Veteran Member
Join Date: Oct 2006
Location: Poland
Old 10-02-2014 , 01:49   Re: Turn angle in period
Reply With Quote #15

is this what you are trying to do?
PHP Code:
#include <amxmodx>
#include <xs>
#include <fakemeta>

#define INTERVAL 0.3
#define ANGLE_CHANGE 1.0 //degrees
#define BEAM_LEN 100.0

new g_spriteg_beam_lifeFloat:g_origin[3]
new 
Float:g_ideal[3], Float:g_current[3//ideal and current must be normalized

public plugin_init(){
    
register_plugin("Rotate vector""1.0""Sylwester")

    
register_clcmd("set_ideal""set_ideal")
    
register_clcmd("set_current""set_current")
    
g_beam_life floatround(10*INTERVAL)
    
    
set_task(INTERVAL"task_display"0__"b")
}

public 
plugin_precache(){
    
g_sprite precache_model("sprites/laserbeam.spr")
}

public 
set_ideal(id){
    
velocity_by_aim(id,1g_ideal)
    
pev(idpev_origing_origin)
}

public 
set_current(id)
    
velocity_by_aim(id,1g_current)
    
public 
task_display(){
    static 
Float:vec_zero[3]
    if(
xs_vec_equal(g_idealvec_zero) ||  xs_vec_equal(g_currentvec_zero))
        return

    new 
Float:dest[3], Float:multiplied[3]
    
xs_vec_mul_scalar(g_idealBEAM_LENmultiplied)
    
xs_vec_add(g_originmultiplieddest)
    
draw_beam(g_origindestg_beam_life525500)
    
xs_vec_mul_scalar(g_currentBEAM_LENmultiplied)
    
xs_vec_add(g_originmultiplieddest)
    
draw_beam(g_origindestg_beam_life502550)
    
    
rotate_current(g_currentg_idealANGLE_CHANGE)
}

public 
rotate_current(Float:curr[3], Float:ideal[3], Float:angle){
    new 
Float:curr_neg[3], Float:out[3], Float:cross[3]
    if(
floatacos(xs_vec_dot(currideal), degrees) < angle){
        
xs_vec_copy(idealcurr)
        return
    }
    
    
xs_vec_sub(idealcurrout)
    
xs_vec_neg(currcurr_neg)
    
xs_vec_normalize(outout)
    
xs_vec_cross(outcurr_negcross)
    new 
Float:out_len floatsin(angledegrees) / xs_vec_len(cross)
    
xs_vec_mul_scalar(outout_lenout)
    
xs_vec_add(outcurrcurr
    
xs_vec_normalize(currcurr)
}

public 
draw_beam(Float:o1[3], Float:o2[3], lifelwidthrgb){
    
message_begin(MSG_BROADCASTSVC_TEMPENTITY_0)
    
write_byte(TE_BEAMPOINTS)
    
write_coord(floatround(o1[0]))
    
write_coord(floatround(o1[1]))
    
write_coord(floatround(o1[2]))
    
write_coord(floatround(o2[0]))
    
write_coord(floatround(o2[1]))
    
write_coord(floatround(o2[2]))
    
write_short(g_sprite)
    
write_byte(1)
    
write_byte(1)
    
write_byte(life)
    
write_byte(lwidth)
    
write_byte(1)
    
write_byte(r)
    
write_byte(g)
    
write_byte(b)
    
write_byte(100)
    
write_byte(10)
    
message_end()

__________________
Impossible is Nothing

Last edited by Sylwester; 10-02-2014 at 01:51.
Sylwester is offline
.Dare Devil.
Veteran Member
Join Date: Sep 2010
Old 10-02-2014 , 02:00   Re: Turn angle in period
Reply With Quote #16

Quote:
Originally Posted by Sylwester View Post
is this what you are trying to do?
PHP Code:
#include <amxmodx>
#include <xs>
#include <fakemeta>

#define INTERVAL 0.3
#define ANGLE_CHANGE 1.0 //degrees
#define BEAM_LEN 100.0

new g_spriteg_beam_lifeFloat:g_origin[3]
new 
Float:g_ideal[3], Float:g_current[3//ideal and current must be normalized

public plugin_init(){
    
register_plugin("Rotate vector""1.0""Sylwester")

    
register_clcmd("set_ideal""set_ideal")
    
register_clcmd("set_current""set_current")
    
g_beam_life floatround(10*INTERVAL)
    
    
set_task(INTERVAL"task_display"0__"b")
}

public 
plugin_precache(){
    
g_sprite precache_model("sprites/laserbeam.spr")
}

public 
set_ideal(id){
    
velocity_by_aim(id,1g_ideal)
    
pev(idpev_origing_origin)
}

public 
set_current(id)
    
velocity_by_aim(id,1g_current)
    
public 
task_display(){
    static 
Float:vec_zero[3]
    if(
xs_vec_equal(g_idealvec_zero) ||  xs_vec_equal(g_currentvec_zero))
        return

    new 
Float:dest[3], Float:multiplied[3]
    
xs_vec_mul_scalar(g_idealBEAM_LENmultiplied)
    
xs_vec_add(g_originmultiplieddest)
    
draw_beam(g_origindestg_beam_life525500)
    
xs_vec_mul_scalar(g_currentBEAM_LENmultiplied)
    
xs_vec_add(g_originmultiplieddest)
    
draw_beam(g_origindestg_beam_life502550)
    
    
rotate_current(g_currentg_idealANGLE_CHANGE)
}

public 
rotate_current(Float:curr[3], Float:ideal[3], Float:angle){
    new 
Float:curr_neg[3], Float:out[3], Float:cross[3]
    if(
floatacos(xs_vec_dot(currideal), degrees) < angle){
        
xs_vec_copy(idealcurr)
        return
    }
    
    
xs_vec_sub(idealcurrout)
    
xs_vec_neg(currcurr_neg)
    
xs_vec_normalize(outout)
    
xs_vec_cross(outcurr_negcross)
    new 
Float:out_len floatsin(angledegrees) / xs_vec_len(cross)
    
xs_vec_mul_scalar(outout_lenout)
    
xs_vec_add(outcurrcurr
    
xs_vec_normalize(currcurr)
}

public 
draw_beam(Float:o1[3], Float:o2[3], lifelwidthrgb){
    
message_begin(MSG_BROADCASTSVC_TEMPENTITY_0)
    
write_byte(TE_BEAMPOINTS)
    
write_coord(floatround(o1[0]))
    
write_coord(floatround(o1[1]))
    
write_coord(floatround(o1[2]))
    
write_coord(floatround(o2[0]))
    
write_coord(floatround(o2[1]))
    
write_coord(floatround(o2[2]))
    
write_short(g_sprite)
    
write_byte(1)
    
write_byte(1)
    
write_byte(life)
    
write_byte(lwidth)
    
write_byte(1)
    
write_byte(r)
    
write_byte(g)
    
write_byte(b)
    
write_byte(100)
    
write_byte(10)
    
message_end()

Since he is making an npc and he need to call function often then calling all those natives you have in stock is a bit bad idea and he doesn't want that advenced rotation ( if you read his original post ).
.Dare Devil. is offline
Sylwester
Veteran Member
Join Date: Oct 2006
Location: Poland
Old 10-02-2014 , 02:31   Re: Turn angle in period
Reply With Quote #17

What is often? If it's like every 0.05 sec then it's not a problem. If you don't like that many natives then you can easily replace most of xs_vec_* with macros. Even if this is more advanced than what was originally requested, it's still fine because it works.
__________________
Impossible is Nothing
Sylwester is offline
.Dare Devil.
Veteran Member
Join Date: Sep 2010
Old 10-02-2014 , 08:39   Re: Turn angle in period
Reply With Quote #18

Quote:
Originally Posted by Sylwester View Post
What is often? If it's like every 0.05 sec then it's not a problem. If you don't like that many natives then you can easily replace most of xs_vec_* with macros. Even if this is more advanced than what was originally requested, it's still fine because it works.
If you're having 20fps in cs, does that look enjoyable? : P
.Dare Devil. is offline
Sylwester
Veteran Member
Join Date: Oct 2006
Location: Poland
Old 10-02-2014 , 09:22   Re: Turn angle in period
Reply With Quote #19

This has nothing to do with your in-game fps.
__________________
Impossible is Nothing
Sylwester is offline
.Dare Devil.
Veteran Member
Join Date: Sep 2010
Old 10-02-2014 , 11:08   Re: Turn angle in period
Reply With Quote #20

Quote:
Originally Posted by Sylwester View Post
This has nothing to do with your in-game fps.
Not sure if you just didin't get my point or you just have no idea how things work.
.Dare Devil. 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 07:07.


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