Vscripts: player perspective vector [SOLVED]

Quote from ChickenMobile on February 18, 2013, 1:00 amI 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
- Set Measurement Type to "Eye Position"
- Set Entity to Move to the name of your object
- Set Entity to Measure to !player (or wanted player's targetname).
- Set both Measure Reference and Movement Reference to the info_target.
The Forward vector can then be retrieved through:
- Code: Select all
Entities.FindByTarget(null, "name_of_object").GetForwardVector()
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
- Set Measurement Type to "Eye Position"
- Set Entity to Move to the name of your object
- Set Entity to Measure to !player (or wanted player's targetname).
- Set both Measure Reference and Movement Reference to the info_target.
The Forward vector can then be retrieved through:
- Code: Select all
Entities.FindByTarget(null, "name_of_object").GetForwardVector()
Quote from FelixGriffin on February 18, 2013, 9:43 amBut doesn't ent_setname work like !picker in that it fails on non-physically-simulated objects, such as targets?
But doesn't ent_setname work like !picker in that it fails on non-physically-simulated objects, such as targets?
Quote from Idolon on February 18, 2013, 11:09 amThat's actually a very smart idea, Chicken! I messed around with this for a bit, and found a few things:
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:
- Code: Select all
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 lolsourceengineOne 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:
That's actually a very smart idea, Chicken! I messed around with this for a bit, and found a few things:
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:
- Code: Select all
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:
Quote from FelixGriffin on February 18, 2013, 12:00 pmNice! But nota bene: on the Workshop ent_create is a cheat.
Nice! But nota bene: on the Workshop ent_create is a cheat.

Quote from ChickenMobile on February 18, 2013, 5:07 pmFelixGriffin 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.
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.
Quote from Idolon on February 18, 2013, 6:22 pmActually, just having the coords of the player's eye and the player's look position are should be enough to accomplish what I'm doing. Thanks for the advice though!
Actually, just having the coords of the player's eye and the player's look position are should be enough to accomplish what I'm doing. Thanks for the advice though!
Quote from Fracture on February 19, 2013, 9:54 pmim trying to do this same thing, but it keeps saying there is no such attachment.
What is the exact written attachment name?
im trying to do this same thing, but it keeps saying there is no such attachment.
What is the exact written attachment name?
Quote from FelixGriffin on February 19, 2013, 10:09 pmWhat player model are you using? It should be "eyes" (four letters, lowercase, no quotes), but Bendy and possibly the robots lack it.
What player model are you using? It should be "eyes" (four letters, lowercase, no quotes), but Bendy and possibly the robots lack it.
Quote from Fracture on February 19, 2013, 10:12 pmyou mean its not the same for all of them?
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.
you mean its not the same for all of them?
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.