decentraland / decentraland/unity-explorer
[QA] SDK | World position for bone attached entities issue
- Dominant language
- C#
- Stars
- 23
- Forks
- 17
- Avg merge
- 2d 14h
- Merged PRs (30d)
- 94
Description
## Description
When you attach an Entity to the avatar's hand, and try to get the world position of that object, the rotation of the avatar is added twice for some reason, resulting in the world position being off when the avatar is turning away from "North".
## Steps to Reproduce
1. Attach an entity to player's hand:
```ts
AvatarAttach.create(myAttachedEntity, {
anchorPointId: AvatarAnchorPointType.AAPT_RIGHT_HAND
})
```
2. Create a separate sphere entity
3. Add a system that uses `worldPos = getWorldPosition(engine, myAttachedEntity)` and puts the sphere entity on the resulting `worldPos`
4. The sphere will rotate around the avatar **twice as much** as the avatar turns
**Source Code**
```
let myAttachedEntity = engine.addEntity()
Transform.create(myAttachedEntity)
AvatarAttach.create(myAttachedEntity,{
anchorPointId: AvatarAnchorPointType.AAPT_RIGHT_HAND
})
let sphere = engine.addEntity()
Transform.create(sphere, {scale: Vector3.create(0.2, 0.2, 0.2)})
MeshRenderer.setSphere(sphere)
engine.addSystem(()=>{
let worldPos = getWorldPosition(engine, myAttachedEntity)
Transform.getMutable(sphere).position = worldPos
})
```
**Workaround**
```
// WORKAROUND FOR WRIST WORLD POS BUG
export function getHandPosCorrect(handAttachedRootObject:Entity):Vector3{
let playerPos = Transform.get(engine.PlayerEntity).position
let playerRot = Transform.get(engine.PlayerEntity).rotation
let handWorldPosIncorrect = getWorldPosition(engine, handAttachedRootObject)
let handRelativePosIncorrect = Vector3.subtract(handWorldPosIncorrect, playerPos)
let handWorldPosCorrect = Vector3.add(playerPos,Vector3.rotate( handRelativePosIncorrect, QuaternionInvert(playerRot)))
return handWorldPosCorrect
}
```
## Expected Behavior
The sphere should follow the attached entity's world position accurately, without the avatar rotation being applied twice.
## Current Behavior
The rotation is duplicating
https://decentralandteam.slack.com/files/U05FQD5JWH2/F0B2EH1P01K/worldpos.m4v
## System
- Platform: Windows
## Reproduction Index
10/10
## Reporter
Bence
---
Requested by Ani Albano via Slack
Contributor guide
Assessment
This issue has not been assessed yet.