parent entity behaviour effects changed

Please post any questions about developing your plugin here. Please use the search function before posting!
User avatar
Speed0x
Member
Posts: 44
Joined: Sun Feb 05, 2017 4:55 pm
Location: Germany, Hanover
Contact:

parent entity behaviour effects changed

Postby Speed0x » Sun May 27, 2018 5:46 pm

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
User avatar
VinciT
Member
Posts: 63
Joined: Thu Dec 18, 2014 2:41 am

Re: parent entity behaviour effects changed

Postby VinciT » Mon May 28, 2018 1:39 am

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.
User avatar
Speed0x
Member
Posts: 44
Joined: Sun Feb 05, 2017 4:55 pm
Location: Germany, Hanover
Contact:

Re: parent entity behaviour effects changed

Postby Speed0x » Mon May 28, 2018 5:40 am

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..
Last edited by Speed0x on Mon May 28, 2018 9:15 am, edited 4 times in total.
User avatar
Ayuto
Project Leader
Posts: 1833
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Re: parent entity behaviour effects changed

Postby Ayuto » Mon May 28, 2018 4:06 pm

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').
User avatar
Speed0x
Member
Posts: 44
Joined: Sun Feb 05, 2017 4:55 pm
Location: Germany, Hanover
Contact:

Re: parent entity behaviour effects changed

Postby Speed0x » Mon May 28, 2018 5:21 pm

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?
User avatar
VinciT
Member
Posts: 63
Joined: Thu Dec 18, 2014 2:41 am

Re: parent entity behaviour effects changed

Postby VinciT » Mon May 28, 2018 6:51 pm

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.
User avatar
Speed0x
Member
Posts: 44
Joined: Sun Feb 05, 2017 4:55 pm
Location: Germany, Hanover
Contact:

Re: parent entity behaviour effects changed

Postby Speed0x » Mon May 28, 2018 7:03 pm

oh sorry i thought you joined in 2014... and no reason to say sorry btw. no problem at all. that was just my feedback
User avatar
Ayuto
Project Leader
Posts: 1833
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Re: parent entity behaviour effects changed

Postby Ayuto » Tue May 29, 2018 3:48 pm

Did entity.get_key_value_vector('origin') fix your issue?
User avatar
VinciT
Member
Posts: 63
Joined: Thu Dec 18, 2014 2:41 am

Re: parent entity behaviour effects changed

Postby VinciT » Tue May 29, 2018 4:01 pm

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)
User avatar
Ayuto
Project Leader
Posts: 1833
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Re: parent entity behaviour effects changed

Postby Ayuto » Tue May 29, 2018 4:14 pm

Thanks for verifying! I have changed it back to the KeyValue method:
https://github.com/Source-Python-Dev-Te ... 7a0b5c549d
User avatar
Speed0x
Member
Posts: 44
Joined: Sun Feb 05, 2017 4:55 pm
Location: Germany, Hanover
Contact:

Re: parent entity behaviour effects changed

Postby Speed0x » Tue May 29, 2018 4:17 pm

okay it all works thanks

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 2 guests