Vscripts: player perspective vector [SOLVED]

Avatar
Idolon
417 Posts
Posted Feb 16, 2013
I'm currently working on a Vscript to determine a vector that describes the direction the player is looking in. While I can find the X and Y values from using GetPlayer().GetForwardVector(), this doesn't return the Z value (it is always 0). Does anyone know how finding the Z value could be accomplished?

EDIT:
I've solved the issue in a fairly roundabout way with help from ChickenMobile! You can grab the code a few posts down.

Advertisement
Registered users don’t see ads! Register now!
Avatar
CamBen
973 Posts
Posted Feb 16, 2013
Replied 52 minutes later
Can't you just parent some trigger looks to the player and some info targets that are up, down, front, and back? That's probably how I would do it.
Avatar
Idolon
417 Posts
Posted Feb 16, 2013
Replied 45 minutes later
I need an exact number for my uses, unfortunately. However, I do have an alternative idea. Would it be possible to use !picker (or something similar) to find a vector of where the player is looking, relative to the world?
Avatar
FelixGriffin
2,680 Posts
Posted Feb 16, 2013
Replied 15 minutes later
Not unless the player is looking at an appropriate scripted object at all times.

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.

Avatar
Idolon
417 Posts
Posted Feb 16, 2013
Replied 51 minutes later
Parenting to the player's eyes sorta works, but since it's a literal attachment to the "eyes" bone of the player model, it jitters around a lot. I'll e-mail Valve and see if I can get a better solution, and if not, I'll use this technique. Thanks!
Avatar
ChickenMobile
2,460 Posts
Posted Feb 17, 2013
Replied 10 hours later

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)
Avatar
FelixGriffin
2,680 Posts
Posted Feb 17, 2013
Replied 8 hours later
Does that return the Z value, though? I didn't think it did.
Avatar
Idolon
417 Posts
Posted Feb 17, 2013
Replied 2 hours later
It doesn't, unfortunately. Looking up and down doesn't change the player's pitch.
Avatar
Lpfreaky90
2,842 Posts
Posted Feb 17, 2013
Replied 6 minutes later
Totally offtopic: Idolon; what objects are you hiding...
Avatar
CamBen
973 Posts
Posted Feb 17, 2013
Replied 10 hours later
Giant stashes of stolen door from various door-less maps.
Avatar
ChickenMobile
2,460 Posts
Posted Feb 18, 2013
Replied 2 hours later

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:

    Entities.FindByTarget(null, "name_of_object").GetForwardVector()
    
    Avatar
    FelixGriffin
    2,680 Posts
    Posted Feb 18, 2013
    Replied 8 hours later
    But doesn't ent_setname work like !picker in that it fails on non-physically-simulated objects, such as targets?
    Avatar
    Idolon
    417 Posts
    Posted Feb 18, 2013
    Replied 1 hour later
    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:

    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:
    img

    Avatar
    FelixGriffin
    2,680 Posts
    Posted Feb 18, 2013
    Replied 51 minutes later
    Nice! But nota bene: on the Workshop ent_create is a cheat.
    Avatar
    ChickenMobile
    2,460 Posts
    Posted Feb 18, 2013
    Replied 5 hours later

    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.

    Avatar
    Idolon
    417 Posts
    Posted Feb 18, 2013
    Replied 1 hour later
    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!
    Avatar
    Fracture
    797 Posts
    Posted Feb 19, 2013
    Replied 1 day later
    im trying to do this same thing, but it keeps saying there is no such attachment.

    What is the exact written attachment name?

    Avatar
    FelixGriffin
    2,680 Posts
    Posted Feb 19, 2013
    Replied 15 minutes later
    What player model are you using? It should be "eyes" (four letters, lowercase, no quotes), but Bendy and possibly the robots lack it.
    Advertisement
    Registered users don’t see ads! Register now!
    Avatar
    Fracture
    797 Posts
    Posted Feb 19, 2013
    Replied 2 minutes later
    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.