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

Turn angle in period [SOLVED]


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
usaexelent
Senior Member
Join Date: Nov 2009
Location: Lithuania
Old 09-07-2014 , 15:29   Turn angle in period [SOLVED]
Reply With Quote #1

Hello, could someone help me with this code, it works but it only turns in one direction. I'm currently using this code to turn my npc to the required angle by adding 1 degree every think.

PHP Code:
bool:turn_with_speed(Float:current[3],Float:ideal[3]) 
{
    new 
Float:angle current[1]
    new 
Float:tangle ideal[1]

    if(
angle 360// Don't let angle go more then 360 degrees
        
angle 0.0
    
    
if( (angle >= 0.0) && (angle <= 180.0) )
    {
        if( (
360 tangle) <= 180 || angle tangle)
        {
            
angle++
            
client_print(0print_center"Current: %f; Angle: %f; TAngle: %f; I I"current[1], angletangle// For debug purposes
            
console_print(0"I I"// For debug purposes
        
}
        else
        {
            
angle--
            
client_print(0print_center"Current: %f; Angle: %f; TAngle: %f; I II"current[1], angletangle)
            
console_print(0"I II")
        }
    }
    else
    {
        if( (
360 tangle) >= 180 || angle tangle)
        {
            
angle++
            
client_print(0print_center"Current: %f; Angle: %f; TAngle: %f; II I"current[1], angletangle)
            
console_print(0"II I")
        }
        else
        {
            
angle--
            
client_print(0print_center"Current: %f; Angle: %f; TAngle: %f; II II"current[1], angletangle)
            
console_print(0"II II")
        }
    }
    
    if(
is_within_difference(angletangle2.0)) // Check if npc needs to turn.
    
{
        
angle tangle
        
//client_print(0, print_center, "Current: %f; Angle: %f; XX", current[1], angle)
    
}

    
current[1] = angle
    
    
    
return true // function is not created to the end, I'll do it later.

__________________
and once again

Last edited by usaexelent; 10-07-2014 at 20:56.
usaexelent is offline
Send a message via Skype™ to usaexelent
.Dare Devil.
Veteran Member
Join Date: Sep 2010
Old 09-08-2014 , 19:24   Re: Turn angle in period
Reply With Quote #2

try this:
PHP Code:
stock angle_addFloat:angles[3], Float:ideal[3], Float:degree_add[3] )
{
    new 
Float:da
    
for( 03a++ )
    {
        
ideal[a] - angles[a]
        if( 
0.0 )
        {
            if( 
degree_add[a] > * -1.0 angles[a] += d
            
else angles[a] -= degree_add[a]
            continue
        }
        if( 
degree_add[a] > angles[a] += d
        
else angles[a] += degree_add[a]
    }

in your case it would be:
PHP Code:
angle_addcurrentidealFloat:{ 1.01.01.0 } ) 

Last edited by .Dare Devil.; 09-08-2014 at 19:24.
.Dare Devil. is offline
usaexelent
Senior Member
Join Date: Nov 2009
Location: Lithuania
Old 09-08-2014 , 20:22   Re: Turn angle in period
Reply With Quote #3

Doesn't work properly, it only changes pitch, BTW I need only Yaw.

EDITED:

Tried like this,
Code:
stock angle_add( Float:angles[3], Float:ideal[3], Float:degree_add = 1.0 )
{
	new Float:d, a
	d = ideal[1] - angles[1]
	if( d < 0.0 )
	{
		if( degree_add > d * -1.0 ) angles[1] += d
		else angles[1] -= degree_add
	}
	if( degree_add > d ) angles[1] += d
	else angles[1] += degree_add
}
It only turns in one direction and some times turns at once.
__________________
and once again

Last edited by usaexelent; 09-08-2014 at 20:41.
usaexelent is offline
Send a message via Skype™ to usaexelent
.Dare Devil.
Veteran Member
Join Date: Sep 2010
Old 09-09-2014 , 06:59   Re: Turn angle in period
Reply With Quote #4

Quote:
Originally Posted by usaexelent View Post
Doesn't work properly, it only changes pitch, BTW I need only Yaw.

EDITED:

Tried like this,
Code:
stock angle_add( Float:angles[3], Float:ideal[3], Float:degree_add = 1.0 )
{
	new Float:d, a
	d = ideal[1] - angles[1]
	if( d < 0.0 )
	{
		if( degree_add > d * -1.0 ) angles[1] += d
		else angles[1] -= degree_add
	}
	if( degree_add > d ) angles[1] += d
	else angles[1] += degree_add
}
It only turns in one direction and some times turns at once.
I just tested the code i gave you and it worked fine.
.Dare Devil. is offline
usaexelent
Senior Member
Join Date: Nov 2009
Location: Lithuania
Old 09-09-2014 , 07:53   Re: Turn angle in period
Reply With Quote #5

Quote:
Originally Posted by .Dare Devil. View Post
I just tested the code i gave you and it worked fine.
Sorry, tested again, some thing was wrong with my npc, but the problem still remains, your code works exactly the same as mine, it only turn in one direction to reach ideal angle.

I'll send you my npc code to PM, and you can test it, you'll see, BTW thanks for all the help so far.
__________________
and once again

Last edited by usaexelent; 09-09-2014 at 07:54.
usaexelent is offline
Send a message via Skype™ to usaexelent
.Dare Devil.
Veteran Member
Join Date: Sep 2010
Old 09-09-2014 , 07:58   Re: Turn angle in period
Reply With Quote #6

Quote:
Originally Posted by usaexelent View Post
Sorry, tested again, some thing was wrong with my npc, but the problem still remains, your code works exactly the same as mine, it only turn in one direction to reach ideal angle.

I'll send you my npc code to PM, and you can test it, you'll see, BTW thanks for all the help so far.
What do you mean only one direction?
It goes on the direction what is closest to ideal angle. Isin't that what you want?
.Dare Devil. is offline
usaexelent
Senior Member
Join Date: Nov 2009
Location: Lithuania
Old 09-09-2014 , 08:02   Re: Turn angle in period
Reply With Quote #7

Yes, it is what I want, but if ideal Angle is closer to the right side then it turns left side all the way anyway.
__________________
and once again
usaexelent is offline
Send a message via Skype™ to usaexelent
.Dare Devil.
Veteran Member
Join Date: Sep 2010
Old 09-09-2014 , 09:09   Re: Turn angle in period
Reply With Quote #8

i did not test it so im not sure if it works.

PHP Code:
// each time you update your ideal angle, call this function.
// angles is npc angle and ideal is must be angle for npc
stock fix_idealFloat:angles[3], Float:ideal[3] )
{
    new 
Float:da
    
for( 03a++ )
    {
        
ideal[a] - angles[a]
    if( 
180.0 ideal[a] =  0.0 - (ideal[a] - 180.0)
    if( 
< -180.0 ideal[a] =  360.0 - (ideal[a] + 180.0)
    }
}

stock angle_addFloat:angles[3], Float:ideal[3], Float:degree_add[3] )
{
    new 
Float:da
    
for( 03a++ )
    {
        
ideal[a] - angles[a]
        if( 
0.0 )
        {
            if( 
degree_add[a] > * -1.0 angles[a] += d
            
else angles[a] -= degree_add[a]
            continue
        }
        if( 
degree_add[a] > angles[a] += d
        
else angles[a] += degree_add[a]
    }

.Dare Devil. is offline
usaexelent
Senior Member
Join Date: Nov 2009
Location: Lithuania
Old 09-13-2014 , 14:17   Re: Turn angle in period
Reply With Quote #9

Sorry for not replying you sooner but I had work, this code doesn't work properly, sometimes when I set ideal angle it turns to opposite direction.

This is how I get ideal angle:

PHP Code:
stock aim_at_origin(id,Float:target[3],Float:angles[3]) {
    static 
Float:vec[3]
    
pev(id,pev_origin,vec)
    
vec[0] = target[0] - vec[0]
    
vec[1] = target[1] - vec[1]
    
vec[2] = target[2] - vec[2]
    
engfunc(EngFunc_VecToAngles,vec,angles)
    
angles[0] *= -1.0angles[2] = 0.0
}

stock vectorize(input[3],Float:output[3]) {
    
output[0] = float(input[0])
    
output[1] = float(input[1])
    
output[2] = float(input[2])

And then I use it like this:

PHP Code:
                new vc[3]
                
vc[0] = floatround(owner_aim_origin[0])
                
vc[1] = floatround(owner_aim_origin[1])
                
vc[2] = floatround(owner_aim_origin[2])
                    
                static 
Float:vec[3]
                
vectorize(vc,vec)
                    
                static 
Float:targetangle[3]
                
aim_at_origin(ent,vec,targetangle)
                
pev(ent,pev_angles,vec)

                
//if(turn_with_speed(vec,targetangle, 5.0))
                
fix_ideal(vectargetangle)
                
angle_addvectargetangleFloat:{ 1.01.01.0 } )  
                
set_pev(ent,pev_angles,vec
__________________
and once again

Last edited by usaexelent; 09-13-2014 at 14:20.
usaexelent is offline
Send a message via Skype™ to usaexelent
usaexelent
Senior Member
Join Date: Nov 2009
Location: Lithuania
Old 09-29-2014 , 14:22   Re: Turn angle in period
Reply With Quote #10

Common guys, please help me
__________________
and once again
usaexelent is offline
Send a message via Skype™ to usaexelent
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 05:36.


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