Hello, has anyone ever had a problem finding the position of objects relative to other objects? I have a list of modules"proxies" within a certain distance of the one and trying to find out where they border it, north[0] south[1] east,west,up,down ect. I’m getting some really weird results even with the localPositions instead of just transform position within this method assuming all of the proxies are just on the border of the one containing this standard script.
for(int i=0; i < proxies.Count; i++)
{
if(proxies*.transform.localPosition.z != this.transform.localPosition.z)*
{
if(proxies*.transform.localPosition.z > this.transform.localPosition.z)*
sides[0].free = false;
if(proxies*.transform.localPosition.z < this.transform.localPosition.z)*
sides[1].free = false;
}
I repeat this for all directions 0-5.
They are parented to a main.
your parents transform.position
will be game world coordinates, and your children on it will basically have Vector3(0,0,0)
(unless you moved them, or didn’t set them to 0,0,0
). So when calling children coordinates, local space will be adding the offset from zero. Unless of course you’re not calling local and are calling worldspace
, then it’ll be transform.parent.position + localPosition
. And also no need for 'this'
as just declaring transform
will represent the transform to which the script is attached to.
Also not sure what proxies are, as in if they are child-ed or not? But your parent needs normal position, and any children need local from which they are attached to. So if it’s a child of a child, make sure who ever needs to be at Vector3.zero
is there
Ohh you mean trying to find adjacent tiles basically. There is a few ways to go about that, but either way you’re going to need a collision to happen. You could use ray, but sometimes that gives adverse effects. What I do is spawn an invisible cube at:
transform.position + new Vector3(0, 0, distance) // north
transform.position + new Vector3(distance, 0, 0) // east
etc… and have logic in the cube to return object variables it hit and send them back to the class that’s checking. You can do collisionAt, or something I’ve heard of once, but it’s less performant than just using a standard non-rendered-cube.