Hello, I'm working on creating a Living Entity that's composed of multiple entity segments. I've created two Entities, an EntityLeader and an EntitySegment. inside the EntityLeader, I created an Array of EntitySegment and added a method called spawnBodySegments that initializes the array at MAX_SEGMENTS, then for each segment in that array it creates a new EntitySegment, calls setLocationAndAngles, then spawns it into the world.
The problem I'm having is, (I guess) I'm not sure where to call this method (spawnBodySegments). If I call spawnBodySegments from the Constructor or from entityInit(), then when it uses "this.posX" as the base X position for setLocationAndAngles, at this point this.posX = 0.0. The same with Y and Z obviously.
I tried changing onUpdate to check if(this.body == null) at the start of the function then call spawnBodySegments so that it should theoretically only spawn them when onUpdate is first called with a valid set of coordinates. This seemed to work sort of (based on printing the positions and adding breakpoints to view the position values), except when I iterate through the body segments in onUpdate and call leader = this.body[i - 1]; this.body[ i ].setPosition(leader.posX - 0.5D, leader.posY, leader.posZ - 0.5D); -- just testing to try to get an understanding of the math I need to implement. When I call that function, for some strange reason it just keeps changing the position of the EntityLead segment. so even without any AI, with all super functions disabled, whenever I spawn one and let that function do its thing, it just drifts away in the -X and -Z direction and doesn't spawn any visible body segments.
I'm sure it's something stupid I'm overlooking, but I've pulled out some hair over this. Any help would be greatly appreciated.