Raised This Month: $12 Target: $400
 3% 

[HL2DM] Sprite re-parenting offset issue


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
AdRiAnIlloO
Member
Join Date: Jul 2015
Location: Spain
Old 10-10-2021 , 19:12   [HL2DM] Sprite re-parenting offset issue
Reply With Quote #1

Hi people,

I have an overall working feature which puts sprites above a single client's head (among all connected players). To save performance / be efficient, when a different client is designated to have the sprite and it was already created, I simply teleport and re-parent it to the new owner (so instead of e.g. killing & re-creating the sprite). For context, this is for a match server.

Sometimes, there is the issue where the re-parented sprite becomes shifted (horizontally only) from the relative head point where it should be (must be horizontally centered to the player model, and some units above head), possibly when the new player was moving and/or jumping right before the sprite is re-parented to them. This problematic offset is either randomly small and unimportant or too big and therefore annoying for the gameplay, as the sprite is visible to owner and others.

Here's the function that gets called for re-parenting the sprite:

Code:
void ResetKingSprite()
{
	Entity_ClearParent(gKingSprite); // Just a convenient wrapper from SMLib off the expected procedure
	float origin[3], angles[3] = {0.0, 0.0, 0.0};
	GetClientAbsOrigin(gTopScorer, origin); // gTopScorer = new owner client index
	origin[2] += 80.0;
	TeleportEntity(gKingSprite, origin, angles, NULL_VECTOR);
	Entity_SetParent(gKingSprite, gTopScorer); // Just a convenient wrapper from SMLib off the expected procedure
}
A picture might explain better all of this case, though I don't have any where the issue is shown, so I attach one illustrating the ideal sprite placement along some explanation of the issue, for you to get the idea.

Would there be a master way to ensure the sprite is always correctly placed without having any offset? If possible, I'd like to hear from anyone who might dealed with the same concept (not exclusively, ofc).

Any help appreciated. Thanks.
Attached Images
File Type: jpg 20211011010102_1.jpg (69.4 KB, 52 views)

Last edited by AdRiAnIlloO; 10-10-2021 at 19:27.
AdRiAnIlloO is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 10-11-2021 , 16:42   Re: [HL2DM] Sprite re-parenting offset issue
Reply With Quote #2

You are doing all in same frame.
Try request next frame after teleport, then parent or something. My wild guess.

Last edited by Bacardi; 10-11-2021 at 16:42.
Bacardi is offline
AdRiAnIlloO
Member
Join Date: Jul 2015
Location: Spain
Old 10-11-2021 , 16:52   Re: [HL2DM] Sprite re-parenting offset issue
Reply With Quote #3

Quote:
Originally Posted by Bacardi View Post
You are doing all in same frame.
Try request next frame after teleport, then parent or something. My wild guess.
Thanks!

Casually, I had thought the same and already had switched to that approach before posting the thread, but I wanted to expose the original intended code state.

Code:
void ResetKingSprite()
{
	Entity_ClearParent(gKingSprite);
	float origin[3], angles[3] = {0.0, 0.0, 0.0};
	GetClientAbsOrigin(gTopScorer, origin);
	origin[2] += KING_SPRITE_Z_OFFSET;
	TeleportEntity(gKingSprite, origin, angles, NULL_VECTOR);
	RequestFrame(OnKingSpriteTeleported);
	SetKingSpriteVisibility(true);
}

void OnKingSpriteTeleported()
{
	if (gKingSprite != INVALID_ENT_REFERENCE)
	{
		Entity_SetParent(gKingSprite, gTopScorer);
	}
}
I need to play enough more on my server to confirm how it goes out. The problem is, by the obvious nature of this approach (1 frame delay), the resulting effect might already imply there will still be an offset, variable with client's movement/velocity as well, but which might be smaller at least.

Last edited by AdRiAnIlloO; 10-11-2021 at 16:55.
AdRiAnIlloO is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 10-12-2021 , 03:34   Re: [HL2DM] Sprite re-parenting offset issue
Reply With Quote #4

I don't have idea, how accurate are coordinates with client and sprite in same code sequence...
And perhaps 1 frame delay could be too short to fix it, next you could try create timer with 0.1 seconds. Recommend in Valve Wiki dev site in some documents.

Last edited by Bacardi; 10-12-2021 at 03:35.
Bacardi is offline
AdRiAnIlloO
Member
Join Date: Jul 2015
Location: Spain
Old 10-12-2021 , 21:00   Re: [HL2DM] Sprite re-parenting offset issue
Reply With Quote #5

This approach seems to be working flawlessly for now:

Code:
void StartResetKingSprite()
{
	Entity_ClearParent(gKingSprite);
	RequestFrame(EndResetKingSprite);
}

void EndResetKingSprite()
{
	if (gKingSprite != INVALID_ENT_REFERENCE)
	{
		float origin[3], angles[3] = {0.0, 0.0, 0.0};
		GetClientAbsOrigin(gTopScorer, origin);
		origin[2] += KING_SPRITE_Z_OFFSET;
		TeleportEntity(gKingSprite, origin, angles, NULL_VECTOR);
		SetKingSpriteVisibility(true);
		Entity_SetParent(gKingSprite, gTopScorer);
	}
}
So instead of delaying the parenting, I delay everything but the parent clear (by one frame). But I'll inform if it gets affected eventually, too.
AdRiAnIlloO is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 01:10.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode