Vscripts: player perspective vector [SOLVED]
EDIT:
I've solved the issue in a fairly roundabout way with help from ChickenMobile! You can grab the code a few posts down.
If you SetParentAttachmentMaintainOffset something to the !player's "eyes" attachment it moves when they look. You could do that with two info_targets at different distances and subtract their position vectors relative to the player, that would give you what you need.
Wouldn't it be better to get the player angles so you know exactly what way they are looking?
The angles go from 180 to -180 so it would take a little bit to get used to.
local PlayerAng = player.GetAngles()
local PlayerDir = PlayerAng.z
printl(PlayerDir)
I may have some sort of weird solution for this if you also want the pitch.
- Force the player to create an entity such as an info_target (Ent_create info_target)- Name this info_target (Ent_setname name)- Get the coordinates from your origin + the units up to around your view/eye. According to the wiki this is 64 units.- Get the coordinates from the recently named info_target- Use the 2 point - angle formula in order to get the vector (angles xyz) from the player + 64 to the info_target.
### Edit:
2013 ChickenMobile's idea is dumb - 2019 me came up with a much better way: - Create an object you want to mimic player view angles from. This object must be non-solid and/or invisible.- Create an info_target- Create a logic_measure_movement
The Forward vector can then be retrieved through:
Entities.FindByTarget(null, "name_of_object").GetForwardVector()
1) Naming the info_target isn't an option. Since ent_setname is naming what the player is looking at (we can't reference the created info_target directly), the script can actually pick up other ents. I discovered this when I accidentally deleted the very logic_script that was running this script. To fix this, I'm just using some entity that I'll never use in the level, and then finding it via Entities.FindByClassname().
2) Only certain entities work! Some entities only seem to work on flat, horizontal surfaces, and not walls. After experimenting for a while, I discovered that point_laser_target seems to work fine. Most prop_* entities work, but they cause other issues that I didn't want to deal with (missing models, console errors etc).
3) Instead of adding 64 to the z-component of the player origin, you can just take GetPlayer().EyePosition(). It's the same thing, but I thought you should know.
For those curious, here's the code:
SendToConsole("ent_create point_laser_target");
while((ent = Entities.FindByClassname(ent,"point_laser_target"))!= null)
{
playerLookPos <- ent.GetOrigin();
SendToConsole("ent_remove point_laser_target");
}
playerLookPos <- Vector(playerLookPos.x,playerLookPos.y,playerLookPos.z-12.031);
//For some reason the z value is always off by that much, probably has to do with lolsourceengine
One issue is that it always lags behind one step since you can't get the ent's data until a little bit after it's been made, but it pretty much works.
==SOLVED==
(It's still possible that Valve will add the function I requested, but I'm not keeping my fingers crossed)
tl;dr:

FelixGriffin wrote:
Nice! But nota bene: on the Workshop ent_create is a cheat.
Not if you call it through a script?
Idolon, I was trying to get this to work with a cube to copy my angles and I pretty much got it working (with nearly the exact code you have with the checking of the null item in case it didn't spawn and spawning and deleting from a classname) except I had a major problem with mimicking the angles as the link I gave to you is actually only 2D not 3D (sorry).
So you will need to create a matrix in order to get the angles and do some other mathematics and normalizing manually as squirrel doesn't actually have any base vector functions built into the engine (which is incredibly stupid).
I think HMW made this with his sendificator script already, so give him a buzz.
What is the exact written attachment name?
EDIT, I tried this and i see how ridiculously jittery it is as mentioned before, not only that, but the entities ended up being pointed towards the ground.