thedarkmodcommunity / test-latch

0 stars 0 forks source link

Latch not bound to doors open at map start #25

Open FrostSalamander opened 7 months ago

FrostSalamander commented 7 months ago

If you want a door to be open at map start, it will start open but the latch will be floating in mid-air.

I believe the problem is with this line: https://github.com/thedarkmodcommunity/test-latch/blob/816c2b387efe03d2c8c0fb09259cbbc05675244b/script/tdm_latch.script#L288

First of all, the entity's origin spawnarg is used to calculate the move position, and secondly the translate spawnarg is used. Both of these assume the latch is static and will never be in another position other than on a closed door at map start.

Using getWorldOrigin() instead of getVectorKey("origin") fixes the origin problem, but I'm not sure how to fix the translate to move relative to the new position.

FrostSalamander commented 7 months ago

Comments from Dragofer:

When an entity is bound it gets a new local coordinate system where 0,0,0 is the bindmaster's origin (when you use getOrigin()). However, moveToPos and setOrigin both want world coordinates (edited) so the formula for the latch's target coordinates should be:

doorOrigin + ( ( ( latchOffset + ( latchState(0/1) latchTranslate) ) rotated by ( doorRotate spawnarg doorFractionalOpenness ) )

latchOffset is the difference between the origin spawnargs: of the latch minus door latchState is the intended state latchTranslate is the latch's translate spawnarg "rotated by" is achieved with the sys.vecRotate spawnarg for fractional openness there's a dedicated script event