casual-simulation / casualos

Casual Open Simulation for the Web
https://ab1.bot
MIT License
50 stars 9 forks source link

Unexpected behavior with custom dragging & transformer #540

Closed MostlyBen closed 3 months ago

MostlyBen commented 3 months ago

When a bot has a transformer tag (or link) and uses custom dragging to move its transformer, the @onDragging tag receives unexpected values in that.to.

Steps to Reproduce

  1. Create 2 bots
  2. Set one's transformer tag to 🔗{other-bot-id}
  3. On the transformed bot, enable custom dragging to move the transformer
    • @onDrag: @os.enableCustomDragging();
    • @onDragging: @links.transformer.tags.homeY = that.to.y;
  4. Drag the transformed bot around

Both bots will flicker between several homeY values.

MostlyBen commented 3 months ago

Upon further experimentation, I see it's an issue with my code.

that.to in @onDragging is not a global position. It is offset by the transformer's position, and the offset changes when the transformer is moved.

So, to account for this, the @onDragging function should be: links.transformer.tags.homeY = that.to.y + links.transformer.tags.homeY;