Local Entity Position
Blitz3D Forums/Blitz3D Programming/Local Entity Position
| ||
How would I go about finding an entities position(x,y,z) relative to another entities local coordinates? I want to find out if "this object" is to the right or left of "that object" Thanks |
| ||
The Relative Offsets can be achieved just by:X_Offset=EntityX(TargetEntity,True)-EntityX(SourceEntity,True) Y_Offset=EntityY(TargetEntity,True)-EntityY(SourceEntity,True) Z_Offset=EntityZ(TargetEntity,True)-EntityZ(SourceEntity,True) It's important to note the "True" flag addition here, since this ensures you are working with absolute global coordinates, so the correct relative positions can be ascertained. The TargetEntity will be the one you want to know the offset of from the source entity's position. |
| ||
I think that the tform commands may come into play here. You'd want to convert the co-ords of both into co-ords relative to the entity, and it's rotation. If the entity was rotated 90 degrees on the Y axis, the above won't tell you if it's to the left or right, and the numbers will |
| ||
Oh yeah, good point, sorry I think I misread a bit. Ross is rioght, if you need to know a target entity's displacement relative to the position AND orientation of the source, you need to use TFormVector I think you still need the above as that gives you the vector from the world coordinates to transform. I think it should be something like: X_Offset=EntityX(TargetEntity,True)-EntityX(SourceEntity,True) Y_Offset=EntityY(TargetEntity,True)-EntityY(SourceEntity,True) Z_Offset=EntityZ(TargetEntity,True)-EntityZ(SourceEntity,True) TFormVector X_Offset,Y_OFfset,Z_Offset,0,SourceEntity X_Offset=TFormedX() Y_Offset=TFormedX() Z_Offset=TFormedX() But I'm really not too good with the TForm stuff :S |
| ||
To get the DestinationEntity position relative to the Source entity use:tformpoint 0,0,0, SourceEntity, DestinationEntity x# = tformedx() y# = tformedy() z# = tformedz() Note that this take into consideration scaling and rotation. |