Raised This Month: $ Target: $400
 0% 

Getting an origin with angles and distance


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
EagleEye
New Member
Join Date: Jul 2008
Old 06-02-2009 , 11:21   Getting an origin with angles and distance
Reply With Quote #1

Hey I am trying to create a sprite between a player and where the player is aiming. As it is now, it creates a sprite all the way across the map, so I want to limit the distance the sprite can be created.

What I have now is
Code:
new pOrigin[3],tOrigin[3]
get_user_origin(id,pOrigin)
get_user_origin(id,tOrigin,3)

message_begin(MSG_BROADCAST,SVC_TEMPENTITY)
    write_byte(TE_BEAMPOINTS)
    write_coord(pOrigin[0])
    write_coord(pOrigin[1])
    write_coord(pOrigin[2])
    write_coord(tOrigin[0])
    write_coord(tOrigin[1])
    write_coord(tOrigin[2])
What I think I need is some kind of function that will follow angles that you pass it for a distance you pass it and return a origin or vector or something. Is there any such function or any ideas for how to create one?
EagleEye is offline
Old 06-02-2009, 16:02
[X]-RayCat
This message has been deleted by [X]-RayCat.
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 06-02-2009 , 16:12   Re: Getting an origin with angles and distance
Reply With Quote #2

Code:
new pOrigin[3],tOrigin[3]
get_user_origin(id,pOrigin)
get_user_origin(id,tOrigin,3)

if( get_distance(pOrigin, tOriign) > YOUR_DISTANCE )
{
    new vector[3];
    vector[0] = tOrigin[0] - pOrigin[0];
    vector[1] = tOrigin[1] - pOrigin[1];
    vector[2] = tOrigin[2] - pOrigin[2];
    
    new Float:fVector[3];
    IVecFVec(vector, fVector);
    
    new Float:length = vector_length(fVector);
    
    fVector[0] = fVector[0] / length * YOUR_DISTANCE;
    fVector[1] = fVector[1] / length * YOUR_DISTANCE;
    fVector[2] = fVector[2] / length * YOUR_DISTANCE;
    
    FVecIVec(fVector, vector);
    
    tOrigin[0] = pOrigin[0] + vector[0];
    tOrigin[1] = pOrigin[1] + vector[1];
    tOrigin[2] = pOrigin[2] + vector[2];
}

message_begin(MSG_BROADCAST,SVC_TEMPENTITY)
    write_byte(TE_BEAMPOINTS)
    write_coord(pOrigin[0])
    write_coord(pOrigin[1])
    write_coord(pOrigin[2])
    write_coord(tOrigin[0])
    write_coord(tOrigin[1])
    write_coord(tOrigin[2])
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] 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 14:04.


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