Page 1 of 1

parent entity behaviour effects changed

Posted: Sun May 27, 2018 5:46 pm
by Speed0x
in the past i could spawn an entity, parent it to another entity, then call entity.clear_parent() and it would stay at the displayed position.
now i get really weird behaviour..... and sorry, i cannot reconstruct the results from the past, i only know it definately used to work....

so here is the problem currently:

Code: Select all

i spawn an entity. ( ent.origin is somewhere around 0,0,0 )
then i parent it to an entity. ( now the ent.origin is/prints at false coordinates, although it should be near the parent )

and also, it shows the origin correctly visually. but .origin property returns completely off/false position.
here is a rough example of how off it is :

Code: Select all

THIS SHOWS : Vector(917.92626953125, -7709.6591796875, 9075.6396484375)
THIS SHOULD BE :Vector(7142.69482421875, -3331.988037109375, -9038.638671875)

then, if i clear the parent. ent.origin snaps back to (0,0,0). ( which i think in the past it would stay at the parent based/moved position )

does anyone know whats going on here?... thanks

Re: parent entity behaviour effects changed

Posted: Mon May 28, 2018 1:39 am
by VinciT
When you parent an entity to another, the origin changes from world space to local space (space of the parent entity). This is probably why you are getting the false position, you are getting the local origin, not the world origin.

"Every entity's position ('origin') is stored as a vector relative to its parent: you are likely to be familiar with this idea already as Cartesian grid coordinates."
https://developer.valvesoftware.com/wiki/Vector

From that same page, you can see a link to GetAbsOrigin() - this should return the correct origin in your situation, but I don't think that's exposed in SP.

Re: parent entity behaviour effects changed

Posted: Mon May 28, 2018 5:40 am
by Speed0x
okay i found the error. since 1 year, either sp or the engine has changed.

now, i have to clear_parent() before i get and do sthn with the .origin or .angles values of the entity because .origin and .angles properties of the entity are both only overwritten with their correct ( parent translated ) values after clear_parent() is called now. ( 1 year ago, while moving the parent all those child-values would constantly be overwritten and would work with my code, without having to have called clear_parent() in prior)

thanks for whoever may have read the post and tried to help..

Re: parent entity behaviour effects changed

Posted: Mon May 28, 2018 4:06 pm
by Ayuto
There was a change to SP related to the origin property in this PR:
https://github.com/Source-Python-Dev-Te ... n/pull/235

Previously, we retrieved the origin from the KeyValue origin, which called this function (it's the function VinciT mentioned):
https://github.com/alliedmodders/hl2sdk ... 2093-L2102

Now, we retrieve it directly from m_vecOrigin. We might want to change it back to the KeyValue method. For now you can use entity.get_key_value_vector('origin').

Re: parent entity behaviour effects changed

Posted: Mon May 28, 2018 5:21 pm
by Speed0x
yeah i wish he told me, that .origin exactly recently changed. i made very clear that i didn't have the problem before... but he said "I don't think that's exposed in SP.", which sounds like it never was. so that confused me, sorry for spamming this thread a bit.

i think .origin should use getabsorigin() too, why was it changed? although, are there any other scenarios, besides parenting where this creates an issue? i can't think of any. and... in the playerentity it still uses/overwrites getabsorigin for .origin, right?

Re: parent entity behaviour effects changed

Posted: Mon May 28, 2018 6:51 pm
by VinciT
Sorry for not answering your question. I remember having issues getting the proper origin of the weapon model the player was holding before, and I had no idea how to get the absolute origin. Which is why I thought SP didn't expose a way to get the absolute origin.

Re: parent entity behaviour effects changed

Posted: Mon May 28, 2018 7:03 pm
by Speed0x
oh sorry i thought you joined in 2014... and no reason to say sorry btw. no problem at all. that was just my feedback

Re: parent entity behaviour effects changed

Posted: Tue May 29, 2018 3:48 pm
by Ayuto
Did entity.get_key_value_vector('origin') fix your issue?

Re: parent entity behaviour effects changed

Posted: Tue May 29, 2018 4:01 pm
by VinciT
I just tried it and yes, it did. It gave me the absolute origin.

Syntax: Select all

origin: Vector(0.0, 0.0, 0.0)
keyvalue origin: Vector(-1125.4588623046875, -899.1467895507812, 177.48202514648438)

Re: parent entity behaviour effects changed

Posted: Tue May 29, 2018 4:14 pm
by Ayuto
Thanks for verifying! I have changed it back to the KeyValue method:
https://github.com/Source-Python-Dev-Te ... 7a0b5c549d

Re: parent entity behaviour effects changed

Posted: Tue May 29, 2018 4:17 pm
by Speed0x
okay it all works thanks