Head Attachment Point?
FocusedWolf
Join Date: 2005-01-09 Member: 34258Members
in Modding
I'm looking for a reliable way to determine where the top of a player model is. This position would need to adjust based on the <u>visible</u> height of the model.
This won't work because the height doesn't change when crouched:
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->local model = Shared.GetModel(Shared.GetModelIndex(player:GetModelName())) //ya weird code works around the lack of a player:GetModelIndex() function :P
if model then
local min, max = model:GetExtents()
end<!--c2--></div><!--ec2-->
My first approach was eyePos + someOffset but the issue is when the player crouches the name floats like 5 ft over their head.
My second approach was player:GetOrigin() + player:GetViewOffset() + someOffset, and that resulted in a eye position that i think matches where the players camera goes when they crouch or jump or stand etc, but (depending on the player model) when crouched sometimes that camera goes to the chest area or lower (for example the camera for a crouched fade is actually below his crotch).
Almost gave up hope when i found this: player:GetAttachPointOrigin(Weapon.kHumanAttachPoint)
Amazing, Weapon.kHumanAttachPoint = "RHand_Weapon", so calling GetAttachPointOrigin tells me where that right hand is regardless of what the marine is doing. For example he can be crouched or jumping or sprinting or dying (it actually follows his right hand during the death animation :P).
So it's my guess that "RHand_Weapon" is the name of a bone in the marine player model. What's the name of the head bone? If their isn't a consistent name for the head of every player model then consider this a formal request devs :D
This won't work because the height doesn't change when crouched:
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->local model = Shared.GetModel(Shared.GetModelIndex(player:GetModelName())) //ya weird code works around the lack of a player:GetModelIndex() function :P
if model then
local min, max = model:GetExtents()
end<!--c2--></div><!--ec2-->
My first approach was eyePos + someOffset but the issue is when the player crouches the name floats like 5 ft over their head.
My second approach was player:GetOrigin() + player:GetViewOffset() + someOffset, and that resulted in a eye position that i think matches where the players camera goes when they crouch or jump or stand etc, but (depending on the player model) when crouched sometimes that camera goes to the chest area or lower (for example the camera for a crouched fade is actually below his crotch).
Almost gave up hope when i found this: player:GetAttachPointOrigin(Weapon.kHumanAttachPoint)
Amazing, Weapon.kHumanAttachPoint = "RHand_Weapon", so calling GetAttachPointOrigin tells me where that right hand is regardless of what the marine is doing. For example he can be crouched or jumping or sprinting or dying (it actually follows his right hand during the death animation :P).
So it's my guess that "RHand_Weapon" is the name of a bone in the marine player model. What's the name of the head bone? If their isn't a consistent name for the head of every player model then consider this a formal request devs :D
Comments
Just kidding, altough by your descritpion of what you need, it sounds likely ;)
And I dont know what the point is named, but you could try "Head" "anim_attachment_head", "Eye", "Eyes", and obviously the all lowercase versions.
<a href="http://www.wiremod.com/forum/expression-2-discussion-help/14813-e2-entity-attachment-documentation.html" target="_blank">http://www.wiremod.com/forum/expression-2-...umentation.html</a>
This is for several models in hl2 and such.
Marine player... "RHand_Weapon" and "JetPack". I really wish it had "Head", although i may be able to work around this by adding some vectors to the "JetPack" spot.
For skulks, their's the "Bone_Tongue".
AhhhH!!!!!!!!!! the gorge has a "Head" attachment point xD
Fade has "fade_tongue2".
Lerk has "Head_Tongue_02".
Hmm the egg attachment point is called "target".
--------------------------------
<strike>Proposal time. How about all of these weird tongue-name variations just be changed to "Tongue", or "Head". And please give the marine a "Tongue" or "Head" :P</strike>
EDIT: Name it the way you want devs. I'll adapt. :P
I also agree that making all the tongues named in a similar manner is a good idea. Both when it comes to capital letters, and if its simply named Tongue or Head_Tongue or such.
So what are you making anyway? If i may dare to ask
Also, smart idea with using model viewer to get that data, I had completely forgot it existed :P.
Names on players for starters. Health indicators to follow, and some other crazy ideas after that :P
<a href="http://i.imgur.com/rhSho.jpg" target="_blank">http://i.imgur.com/rhSho.jpg</a>
<a href="http://i.imgur.com/OiJbA.jpg" target="_blank">http://i.imgur.com/OiJbA.jpg</a>
<a href="http://i.imgur.com/F3wjr.jpg" target="_blank">http://i.imgur.com/F3wjr.jpg</a>
The graphics are mostly placeholders. Also this placement of names/icons is working off of eyepos + offset vector, at the moment anyway.
Looks pretty cool, I can imagine that the indicators above assist items make it easyer to find them when dropped in infested areas?
EDIT: this is the new code: <a href="http://pastebin.com/w23U3sCD" target="_blank">http://pastebin.com/w23U3sCD</a>
<!--quoteo(post=1860303:date=Jul 13 2011, 05:29 AM:name=Taxen0)--><div class='quotetop'>QUOTE (Taxen0 @ Jul 13 2011, 05:29 AM) <a href="index.php?act=findpost&pid=1860303"><{POST_SNAPBACK}></a></div><div class='quotemain'><!--quotec-->that looks really nice! hope it makes it into the game. maybe only for squad-mated once they get squads right =)<!--QuoteEnd--></div><!--QuoteEEnd-->
Ya it's on the todo to find a way to incorporate squad colors. But only indicate for people in your squad? Hmm. Not very useful right now considering how small teams are. Maybe when it's like 32 vs 32 that would be better :P
<!--quoteo(post=1860338:date=Jul 13 2011, 07:17 AM:name=Feha)--><div class='quotetop'>QUOTE (Feha @ Jul 13 2011, 07:17 AM) <a href="index.php?act=findpost&pid=1860338"><{POST_SNAPBACK}></a></div><div class='quotemain'><!--quotec-->I suggest that you make mic icon over team members head when they use the mic. Sort of like in gmod (or any source game I think).
Looks pretty cool, I can imagine that the indicators above assist items make it easyer to find them when dropped in infested areas?<!--QuoteEnd--></div><!--QuoteEEnd-->
Added to todo list :P
Also yes it works wonders when infestation obscures everything:
Off: <a href="http://i.imgur.com/B78mV.jpg" target="_blank">http://i.imgur.com/B78mV.jpg</a>
On: <a href="http://i.imgur.com/X7TUd.jpg" target="_blank">http://i.imgur.com/X7TUd.jpg</a>
Off: <a href="http://i.imgur.com/9DnUz.jpg" target="_blank">http://i.imgur.com/9DnUz.jpg</a> Not so obvious when the power is out :P
On: <a href="http://i.imgur.com/D1Mco.jpg" target="_blank">http://i.imgur.com/D1Mco.jpg</a>
Firstly, you got lots of elseif-statements in your code, those could be replaced by a table (you got the minimap file open? Well look near the top page for "ClassToGrid". It is a way to use tables instead of lots of elseifs), where the class string is the index, and the value is the name of the attachment point. If you need offsets, the value can be a table with both the name and the vector offset.
Then, instead of lots of functions each using entity:isa(classString) you simply do TableWithValues[player:GetClassName()] to get the value from the table. Or use a single function to get the data.
Sort of the code you want (not tested, and you will want to extend the table with more classes, and such):
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->local TableWithValues = {}
TableWithValues["Marine"] = { "JetPack", Vector(0, -0.35, -0.37), Vector(0, 0.2, -0.37) }
TableWithValues["Gorge"] = { "Head", Vector(0, 0, 0), Vector(0, 0, 0) } //would not need those offsets at all, if you use a "if not value then" check before you would use them
local function GetBlahByClass(class)
if not TableWithValues[class] then return end
return unpack(TableWithValues[class])
end
local function GetPlayerNameAndImageAttachmentPoints(playerEntity)
local nameAttachmentPoint = nil // Should not need to do "= nil", as you are creating the variable here (local)
local imageAttachmentPoint = nil
local attachment, nameOffset, imageOffset = GetBlahByClass(player:GetClassName())
if attachment then //Supid me did "if not attachment" here before, was thinking very wrong :P
local attachPointOrigin, success = playerEntity:GetAttachPointOrigin(attachment)
if (success) then
local attachPointCoords = playerEntity:GetAttachPointCoords(attachment)
//I assume that attachPointCoords.xAxis returns a directional vector of the players forward, yAxis is up, and zAxis is to players right?
nameAttachmentPoint = attachPointOrigin + nameOffset.x * attachPointCoords.xAxis +
nameOffset.y * attachPointCoords.yAxis +
nameOffset.z * attachPointCoords.zAxis
imageAttachmentPoint = attachPointOrigin + imageOffset .x * attachPointCoords.xAxis +
imageOffset .y * attachPointCoords.yAxis +
imageOffset .z * attachPointCoords.zAxis
end
else //default to something for unknown model
nameAttachmentPoint = playerEntity:GetOrigin() + playerEntity:GetViewOffset() + Vector(0,.8,0)
imageAttachmentPoint = playerEntity:GetOrigin() + playerEntity:GetViewOffset()
end
return nameAttachmentPoint,imageAttachmentPoint
end<!--c2--></div><!--ec2-->
EDIT:
I think the things would be even more noticeable if the mes + was blue or blue-green, and the ammo wasnt yellow (emergency lighting is red, di is yellowish/orange). Maybe purplish? Depends on what you set the med-packs to tbh.
And how does the name and image things work for skulks on a wall? Will the text rotate with it, or will it be place on the skulks local up (which might be sideways) and then have text go inside it? :P
EDIT2:
Looking at your code again, I see that you make the mode work on rr players to, which altough they got the rr class might have any model.
This proves a problem in my example code, but you could fix it by not using class names as index, and insead use the model name, and instead of getting players class, you get players model (playerEntity:GetModelName()).
You dont want the functionality for the classes anyway, you want it for the models they use :P.
<!--quoteo(post=1860412:date=Jul 13 2011, 02:44 PM:name=Feha)--><div class='quotetop'>QUOTE (Feha @ Jul 13 2011, 02:44 PM) <a href="index.php?act=findpost&pid=1860412"><{POST_SNAPBACK}></a></div><div class='quotemain'><!--quotec-->I think the things would be even more noticeable if the mes + was blue or blue-green, and the ammo wasnt yellow (emergency lighting is red, di is yellowish/orange). Maybe purplish? Depends on what you set the med-packs to tbh.<!--QuoteEnd--></div><!--QuoteEEnd-->
Ya the colors need some tuning. Imagine having different color sets that turn on when you enter dark rooms :P
<!--quoteo(post=1860412:date=Jul 13 2011, 02:44 PM:name=Feha)--><div class='quotetop'>QUOTE (Feha @ Jul 13 2011, 02:44 PM) <a href="index.php?act=findpost&pid=1860412"><{POST_SNAPBACK}></a></div><div class='quotemain'><!--quotec-->And how does the name and image things work for skulks on a wall? Will the text rotate with it, or will it be place on the skulks local up (which might be sideways) and then have text go inside it? :P<!--QuoteEnd--></div><!--QuoteEEnd-->
The text is always left to right. To test if their's an overlap of the name + image i compare the WorldToScreen coordinates (subtract the y's and see if the difference is greater then some minimum distance) and if overlapping to simply move the name's screen position up a minimum distance. I imagine the same code should work for skulks on walls :P
<!--quoteo(post=1860412:date=Jul 13 2011, 02:44 PM:name=Feha)--><div class='quotetop'>QUOTE (Feha @ Jul 13 2011, 02:44 PM) <a href="index.php?act=findpost&pid=1860412"><{POST_SNAPBACK}></a></div><div class='quotemain'><!--quotec-->Looking at your code again, I see that you make the mode work on rr players to, which altough they got the rr class might have any model.
This proves a problem in my example code, but you could fix it by not using class names as index, and insead use the model name, and instead of getting players class, you get players model (playerEntity:GetModelName()).
You dont want the functionality for the classes anyway, you want it for the models they use :P.<!--QuoteEnd--></div><!--QuoteEEnd-->
At the time i sort of thought isa("ReadyRoomPlayer") would execute faster then GetModelName() + doing string comparisons. Wish i had some way to time the code to make a better determination.
I am not sure on the performance, but imho the readability is so much better that even if it does lag significantly more (which I doubt it does, maybe slightly more, but not noticeable), I would say it is worth it.
What you were doing before during rr sessions was several if statements (unless they were marines as then the first would result true) where you used functions (with if statements inside them) to get class, then model, then compare 2 strings.
My code would just get model, lookup in a table, then some error handling.
So I got no idea if it would lag less or more, but as I said, if it lags more, I doubt it would be significant)
Also, about your wish, I am not sure, but there should be a library called os. So I think you can use os.Clock(), a benchmark, then os.Clock again and calculate the delta.
Locals are also a good way to optimize your code, but make sure you use them correctly for example:
Bad:
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->for k, ent in ipairs(enttbl) do
local classname = ent:GetClassName();
//stuff
end<!--c2--></div><!--ec2-->
Good
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->local classname;
for k, ent in ipairs(enttbl) do
classname = ent:GetClassName();
//stuff
end<!--c2--></div><!--ec2-->
Also if you need to call a global function alot, make a local copy or store its result example:
Bad:
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->for n=1, 100, 1 do
Shared.Message(Client.GetLocalPlayer():GetName());
end<!--c2--></div><!--ec2-->
Good:
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->local Msg = Shared.Message;
local lply = Client.GetLocalPlayer();
for n=1, 100, 1 do
Msg(lply:GetName());
end<!--c2--></div><!--ec2-->
Remember, a function must be looked up everytime its called unless it is a local. Even then calling a function takes about as much time as a table lookup (unless the table is particularly big <= 50 entries)
Lua is pretty fast on its own and NS2 has LuaJIT integrated which significantly increases its performance. Still, if you write a lot of code and if that code is executed a lot (like once per frame) this stuff will make a difference. Its also good practice.
<!--quoteo(post=1860445:date=Jul 13 2011, 05:08 PM:name=Feha)--><div class='quotetop'>QUOTE (Feha @ Jul 13 2011, 05:08 PM) <a href="index.php?act=findpost&pid=1860445"><{POST_SNAPBACK}></a></div><div class='quotemain'><!--quotec-->I meant that the text would go inside the skulk, not the image :P<!--QuoteEnd--></div><!--QuoteEEnd-->
Ahh. Well in that case, no it won't go inside the skulk. Those icon's are GUIGraphicItem's rendering on the screen (z-distance = 0 from screen) so it's actually not rendering on the objects. What you're seeing is an illusion. Basically the images scale down in size based on the distance between the player and object. This is basically an advanced variation of GUIPlayerNames.lua (the way the game draws player names <i>under</i> players when viewed from commander view).
<!--quoteo(post=1860445:date=Jul 13 2011, 05:08 PM:name=Feha)--><div class='quotetop'>QUOTE (Feha @ Jul 13 2011, 05:08 PM) <a href="index.php?act=findpost&pid=1860445"><{POST_SNAPBACK}></a></div><div class='quotemain'><!--quotec-->Also, about your wish, I am not sure, but there should be a library called os. So I think you can use os.Clock(), a benchmark, then os.Clock again and calculate the delta.<!--QuoteEnd--></div><!--QuoteEEnd-->
I once tried this and was mostly getting a deltaTime of 0 so i sort of brushed it off thinking it didn't have the resolution to time the code, not sure:
<a href="http://pastebin.com/m8XtB1RX" target="_blank">http://pastebin.com/m8XtB1RX</a>
And I thought you used something similar to 2d3d in gmod. But ok, that sounds more like drawing on screen using WorldToScreen(vector). :P
<!--quoteo(post=1860452:date=Jul 13 2011, 10:35 PM:name=Slight)--><div class='quotetop'>QUOTE (Slight @ Jul 13 2011, 10:35 PM) <a href="index.php?act=findpost&pid=1860452"><{POST_SNAPBACK}></a></div><div class='quotemain'><!--quotec-->Using a string table lookup is about 10x faster than doing a bunch of else ifs with function calls. A single function call is slightly more expensive than a single table lookup.<!--QuoteEnd--></div><!--QuoteEEnd-->
Thanks for the info. :)
<a href="http://i.imgur.com/6vtDV.jpg" target="_blank">http://i.imgur.com/6vtDV.jpg</a> ok on ground
<a href="http://i.imgur.com/upo6V.jpg" target="_blank">http://i.imgur.com/upo6V.jpg</a> not ok on wall
<a href="http://i.imgur.com/n3K7n.jpg" target="_blank">http://i.imgur.com/n3K7n.jpg</a> not ok on ceiling
It <b>had</b> LuaJIT integrated you mean. Max switched to vanilla lua because he wanted to modify the VM to add VM instructions for vectors and stack allocation for them. Idk if he ever actually did these or if they really made any difference.
Hopefully a dev will notice this thread, and post something helpful, maybe it will even like the suggestion to get points like "Head" for all player models. Please? :)
EDIT 2: squad color support is in:
<a href="http://i.imgur.com/sCuAe.jpg" target="_blank">http://i.imgur.com/sCuAe.jpg</a> on
<a href="http://i.imgur.com/JI8sc.jpg" target="_blank">http://i.imgur.com/JI8sc.jpg</a> off
<a href="http://i.imgur.com/pYcTh.jpg" target="_blank">http://i.imgur.com/pYcTh.jpg</a> on
<a href="http://i.imgur.com/VZgBz.jpg" target="_blank">http://i.imgur.com/VZgBz.jpg</a> off
The original colors are very hard to look at so their's hsv conversion to lower the saturation. Only thing that sucks when doing this is blue becomes very purple, as seen in the <a href="http://i.imgur.com/pYcTh.jpg" target="_blank">last group on the right</a>.
BUT
i think it would be awesome to have this in the specatator mode, perhaps merge with the other specatator mod?
But don't put it on always. I suggest using the starcraft approach of pressing ALT to show that additional information. Perhaps even with a healt/armor bar? I'm sure NS2HD would go crazy over this :)
and I have lots of spare time currently :D
@asra, I think you misunderstood it. wulf is not the one who made this mod, he just said that his own recording mod currently eat a lot cpu on the server, and that something in this thread might help him optimize it. This mod however, does not lag afaik.
Speaking of which wulf, want to share what your idea for how to increasing the performance? :)
What i was refering too is that i personaly don't like to have all those things floating around when playing. Makes ns2 look.. not cheap, but very artificial. You lose immersion.
However, while it is not something i would like while playing, it is something i would love to have while spectating, specially if its toggable like the infos in SC2 (the ALT key).
The reason there are attach points on most aliens heads and not the marine is because some effects or projectiles are generated from those points whereas the marine uses muzzle flash for it's weapon effects. BUT don't be surprised if you see "Head" attach point on the marine in the next build!
The "target" attach point is on each building so things like sentries and hydras know where to shoot.
For those ppl making custom models, you can add an attach point by entering this line to a .model_compile file:
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->attach_point "[bone name]"<!--c2--></div><!--ec2-->
Cool mod btw!
<!--quoteo(post=1865597:date=Aug 1 2011, 09:44 PM:name=Chops)--><div class='quotetop'>QUOTE (Chops @ Aug 1 2011, 09:44 PM) <a href="index.php?act=findpost&pid=1865597"><{POST_SNAPBACK}></a></div><div class='quotemain'><!--quotec-->BUT don't be surprised if you see "Head" attach point on the marine in the next build!
Cool mod btw!<!--QuoteEnd--></div><!--QuoteEEnd-->
Thx!. It's official. The marines now have <a href="http://i.imgur.com/GpBNU.png" target="_blank">heads</a>! xD