Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GetBonePosition and GetBoneMatrix on the player clientside during server lag or hiccups will return the position on the server instead of on the client #884

Open
CapsAdmin opened this issue Mar 16, 2014 · 7 comments

Comments

@CapsAdmin
Copy link

This is bad when using these functions to make something follow the player (like a hat)

@thedaneeffect
Copy link

Until this is resolved, personally what I would do is create a model that has no actual mesh, and is just a bone merge-able skeleton. Maybe one that only has a ValveBiped.Bip01_Head1 bone.

Give each player their own clientside instance of this model, bonemerge it to them, and then parent the hat to that ClientsideModel.

💌

@robotboy655
Copy link
Contributor

I am not sure if studiomdl.exe will allow you to compile a model without mesh.

@CapsAdmin
Copy link
Author

@thedaneeffect Interesting workaround. I'll probably make a toggleable clientside fix that does this with the players player model.

@robotboy655 Sorry, I don't see what that has to do with this.

@robotboy655
Copy link
Contributor

@CapsAdmin, It is a reply to that suggested workaround.

@thedaneeffect
Copy link

@robotboy655
I think it should if you include the $bonemerge keyvalue in the .QC like
$bonemerge ValveBiped.Bip01_Head1

I know you can for sure, because I made a view model before that had not a single vertex and I got it to compile successfully, and bonemerge in-game. :)

@CapsAdmin
I made a thing. It's exactly what I was talking about.

bm_head.smd

version 1
nodes
0 "ValveBiped.Bip01_Head1" -1
end
skeleton
time 0
0 0.000000 0.000000 0.000000 0.000000 -0.000000 0.000000
end

bm_head.qc

$modelname "bm_head.mdl"
$body body "bm_head.smd"
$sequence "reference" "bm_head.smd" loop fps 1
$bonemerge "ValveBiped.Bip01_Head1"

If you're on windows, I made a batch for just typing in the .qc name without extension. (You can do sub-directories too like 'subfolder/another/file')

@echo off
set drive=C
set common=%drive%:\Program Files (x86)\Steam\SteamApps\common\
set studiomdl=%common%Counter-Strike Source\bin\studiomdl.exe
set game=%common%GarrysMod\garrysmod\

:input
echo Enter a .QC name.
set /p name="] " %=%
"%studiomdl%" -game "%game%" "%name%.qc"
pause
cls
goto input

Entity

AddCSLuaFile()

DEFINE_BASECLASS( "base_anim" )

ENT.PrintName               = "Bonemerge Test";

ENT.Spawnable               = true;
ENT.AdminOnly               = false;

ENT.RenderGroup             = RENDERGROUP_TRANSLUCENT;
ENT.AutomaticFrameAdvance   = true;

function ENT:SpawnFunction( ply, tr, ClassName )

    if ( !tr.Hit ) then return end

    local SpawnPos = tr.HitPos + tr.HitNormal * 64;

    local ent = ents.Create( ClassName )
        ent:SetPos( SpawnPos )
    ent:Spawn()
    ent:Activate()

    ent:GetPhysicsObject():Sleep();

    return ent

end

local function Merge( Entity, Parent )
    Entity:AddEffects( EF_BONEMERGE );
    Entity:SetParent( Parent );
    Entity:SetMoveType( MOVETYPE_NONE );
    Parent:CallOnRemove( tostring( Entity ), function() Entity:Remove() end );
    return Entity;
end

function ENT:Initialize()
    if ( SERVER ) then
        local size = 32;

        self:SetModel( "models/alyx.mdl" )
        self:PhysicsInitSphere( size )

        local phys = self:GetPhysicsObject()

        if (phys:IsValid()) then
            phys:Wake()
        end

        self:SetCollisionBounds( Vector( -size, -size, -size ), Vector( size, size, size ) )
    else
        self.m_Head = Merge( ClientsideModel( "models/bm_head.mdl" ), self );

        -- We're going to attach a non-bonemerge-able model with our custom bonemerge model.
        self.m_Model = ClientsideModel( "models/props_junk/PlasticCrate01a.mdl" );
        self.m_Model:SetParent( self.m_Head );

        self:CallOnRemove( tostring( self.m_Model ), function() self.m_Model:Remove() end );
    end
end

Here's a picture of what all of this produces: http://puu.sh/7HKRu/1dbf5970ae.png

You can adjust the relative position and angles of the prop simply by setting :SetAngles() and :SetPos()

Edit: I always end up putting so much time into things like this... I read this and suddenly got the idea originally posted. Turns out it works perfectly with any prop and I just made this http://puu.sh/7HLSc/fbf11dede5.png IT'S SO CUTE

@chelog
Copy link

chelog commented Jan 26, 2019

Any success on fixing it 5 years later? Still having some issues with my custom camera thingies and waiting for the fix ;)

@Earu
Copy link

Earu commented Mar 27, 2024

Any news on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants