Jump to content

Sync x,y,z coordinates of two entities


Recommended Posts

Greetings!

I try to get the following to work:

I have an item that should have an effect around it. It's an orb and wherever it is, a fog should surround it.

So if a player takes the orb, the fog is around the player, if the orb is in a chest, it should surround the chest, etc.

I get the entity that has the orb (if any) by calling

inst.inventoryitem:GetGrandOwner()

In the case of nil, there simply is no owner and i use the coordinates of the orb itself instead. A workaround for backpacks is in the works (as they do not count as GrandOwner when placed on the ground), but that's not the issue here.

My problem is, that i do not know how to bind the location of the fog to another entity. As of now, i know the following (not ideal) solutions:

1. Use SetParent to attach the fog to the relevant entity (player, chest, orb, etc.). This is not ideal, because the fog changes directions, when a player turns around, which looks stupid. Also if the player scales (like wolfgang getting mighty) then the fog increases in size as well, which is problematic, because the fog indicates the range in which the orb functions.

2. Use a DoPeriodicTask(0, function) and make use of Transform:SetPosition to set the fog coordinates. This works well if nothing is going on in the world, but if you play with lots of entities, it is often the case, that the fog lags behind the holder of the orb.


I don't know of any other way to solve the problem at hand. In the best case it works like SetParent, but it does not scale and changes direction, when the parent does so.

Any ideas?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
  • Create New...