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

Help with a bit of difficult code


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
OmgHi
Junior Member
Join Date: Jan 2007
Old 09-29-2008 , 12:34   Help with a bit of difficult code
Reply With Quote #1

Solved

Last edited by OmgHi; 10-02-2008 at 07:33.
OmgHi is offline
Prajch
Senior Member
Join Date: Dec 2007
Location: anger++
Old 09-29-2008 , 13:41   Re: Help with a bit of difficult code
Reply With Quote #2

Quote:
Originally Posted by OmgHi View Post
Also, if I've created a message using the message_begin/end, is it possible to delete the message prematurely, before it's life expires, after it's already been created?
PHP Code:
#define TE_KILLBEAM                 99       // Kill all beams attached to entity
// write_byte(TE_KILLBEAM)
// write_short(entity) 
That'll probably only work if you used TE_BEAMENTPOINT or TE_BEAMENTS, so that one end of the beam is attached to the player.

You can't exactly "slow the beam down", but what you can do is draw multiple beam segments, one after another, with the beginning of the next beam starting from the end of the one drawn before it. The number of segments you draw will determine how smooth it looks.

When you get the aim point of a player (either using a traceline or get_user_origin with the right mode), by default you can only draw a beam from the player to that point, so you have to do a little bit of math.

Let's say you have the origin of the player, and the coordinates of the point where their aim hits a wall/entity. Subtracting the initial coordinates from the final coordinates, you get a vector from the player to the point. Now you can modify the length of this vector by dividing each coordinate (x, y, z) by the same amount. If you divide them by the length of the vector itself, you get a "unit vector", or a line of length 1 that still points in the same direction.

So, using something like get_distance() and then doing some division, you get a unit vector in the direction of your aim. Now you can multiply each coordinate by whatever number you want. If you want the beam to be 20 units long, multiple each coordinate by 20.

Now you want the point where the vector you just made ends. To do this, add the coordinates of your player origin to the coordinates of the vector (if you do this on a graph with arrows you can see why it works out with a bit of practice). Finally, draw a beam from the origin to the point you just calculated.

If you store this new end point, you can repeat the process, only using the previous end point as your "player origin". You'll end up with a bunch of line segments connected to each other. If you want this to be a "slow" beam, you'll have to use set_task() or create a timer entity and draw beams when it thinks.

The problem with all this is that you're going to have to draw beams from one points to another, not from an entity to a point. Thus, you'll have to use TE_BEAMPOINTS, which I don't think you can kill using TE_KILLBEAM. Luckily, you can set the lifetime of your beams to 0.1 and just redraw them as many times as you want, rather than drawing a beam with a lifetime of 20 seconds and killing it when you don't need it anymore.

If any of this doesn't make sense, feel free to ask again.
Prajch is offline
OmgHi
Junior Member
Join Date: Jan 2007
Old 10-01-2008 , 10:17   Re: Help with a bit of difficult code
Reply With Quote #3

Solved.
__________________
+karma ftw

Last edited by OmgHi; 10-02-2008 at 07:34.
OmgHi 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 23:20.


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