Skip to content

Commit

Permalink
NPC avatars better example
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas Earnshaw <[email protected]>
  • Loading branch information
nearnshaw authored Dec 2, 2024
1 parent ab81d94 commit efdaaab
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions content/creator/sdk7/interactivity/npc-avatars.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,26 +80,26 @@ Transform.create(myAvatar, {

## Copy wearables from player

The following snippet creates an NPC avatar that uses the same wearables that the player currently has on. This could be used in a scene as a manequin, to show off a particular wearable or emote combined with the player's current outfit.
The following snippet changes the wearables and other characteristics of an NPC avatar to match those that the player currently has on. This could be used in a scene as a manequin, to show off a particular wearable or emote combined with the player's current outfit.

```ts
import { getPlayer } from '@dcl/sdk/src/players'

export function main() {
let userData = getPlayer()
console.log(userData)

if (!userData || !userData.wearables) return
export function swapAvatar(avatar: Entity) {

const myAvatar = engine.addEntity()
AvatarShape.create(myAvatar, {
id: 'Manequin',
emotes: [],
wearables: userData.wearables,
})
let userData = getPlayer()
console.log(userData)

Transform.create(myAvatar, {
position: Vector3.create(4, 0.25, 5),
})
if (!userData || !userData.wearables) return

const mutableAvatar = AvatarShape.getMutable(avatar)

mutableAvatar.wearables = userData.wearables
mutableAvatar.bodyShape = userData.avatar?.bodyShapeUrn
mutableAvatar.eyeColor = userData.avatar?.eyesColor
mutableAvatar.skinColor = userData.avatar?.skinColor
mutableAvatar.hairColor = userData.avatar?.hairColor

}
```

0 comments on commit efdaaab

Please sign in to comment.