AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Getting an origin with angles and distance (https://forums.alliedmods.net/showthread.php?t=93773)

EagleEye 06-02-2009 11:21

Getting an origin with angles and distance
 
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?

Exolent[jNr] 06-02-2009 16:12

Re: Getting an origin with angles and distance
 
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])



All times are GMT -4. The time now is 14:04.

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