Back

Avatar

Face Emote

Singleplayer
Multiplayer

Create a new script component "ChangeEmote" and add it to the DefaultPlayer.

Add the method "PlayEmote" to the script with the parameter emoteType(string) and duration(number).

Set the PlayEmote method's execution space to "Client Only".

Add the event "KeyDownEvent" to the script.

Set the HandleKeyDownEvent's execution space to "Client Only".

Add the code inside the PlayEmote and HandleKeyDownEvent like below.


structChangeEmote

Method:
    [client only]
    void PlayEmote( string emoteType, number duration )
    {
        self.Entity.AvatarRendererComponent:PlayEmotion(EmotionalType[emoteType], duration)
    }


Event Handler:
    [client only] [service] (InputService)
    HandleKeyDownEvent( KeyDownEvent event )
    {
        if not isvalid(self.Entity.AvatarRendererComponent) then return end

        if event.key == KeyboardKey.Alpha1 then
            self:PlayEmote("Smile", 3)
            return
        end

        if event.key == KeyboardKey.Alpha2 then
            self:PlayEmote("Cry", 3)
            return
        end

        if event.key == KeyboardKey.Alpha3 then
            self:PlayEmote("Angry", 3)
            return
        end
    }
                    

Press Play and you can now change the players face emotions by pressing the keys 1, 2 or 3.

Create a new script component "ChangeEmote" and add it to the DefaultPlayer.

Add the method "PlayEmote" to the script with the parameter emoteType(string) and duration(number).

Set the PlayEmote method's execution space to "Server".

Add the event "KeyDownEvent" to the script.

Set the HandleKeyDownEvent's execution space to "Client Only".

Add the code inside the PlayEmote and HandleKeyDownEvent like below.


structChangeEmote

Method:
    [server]
    void PlayEmote( string emoteType, number duration )
    {
        if senderUserId ~= self.Entity.PlayerComponent.UserId then return end
        self.Entity.AvatarRendererComponent:PlayEmotion(EmotionalType[emoteType], duration)
    }


Event Handler:
    [client only] [service] (InputService)
    HandleKeyDownEvent( KeyDownEvent event )
    {
        if not isvalid(self.Entity.AvatarRendererComponent) then return end

        if event.key == KeyboardKey.Alpha1 then
            self:PlayEmote("Smile", 3)
            return
        end

        if event.key == KeyboardKey.Alpha2 then
            self:PlayEmote("Cry", 3)
            return
        end

        if event.key == KeyboardKey.Alpha3 then
            self:PlayEmote("Angry", 3)
            return
        end
    }
                    

Press Play and you can now change the players face emotions by pressing the keys 1, 2 or 3.


Here is a list of emotions available:

Name

Images

Glitter

glitter

Angry

angry

Wink

wink

Bowing

bowing

Smile

smile

Cheers

cheers

Pain

pain

Default

default

Love

love

Oops

oops

Bewildered

bewildered

qBlue

qblue

Vomit

vomit

Troubled

troubled

Stunned

stunned

Hit

hit

Cry

cry

Blaze

blaze

Shine

shine

Hum

hum

Hot

hot

Dam

dam

Chu

chu

Despair

despair

Add Avatar

Create a new empty entity: Create Entity -> Create Empty.

Add a TransformComponent to your entity.

Add a AvatarRendererComponent to your entity.

Add a CostumeManagerComponent to your entity.

You should now see a entity that looks like your own avatar.

Change Avatar Equipment

On the CostumeManagerComponent, press the dot to the right of the textfield.

Select a costume and it will now be used on your avatar.

You should now see the avatar have the costume equipped.

Change Avatar Animation

Singleplayer
Multiplayer

Create a new script component "ChangeAvatarAnimation" and add it to the DefaultPlayer.

Add the method "PlayActionState" to the script with the parameter actionName(string), playRate(number) and spriteAnimClipPlayType(string).

Set the PlayActionState method's execution space to "Client Only".

Add the event "KeyDownEvent" to the script.

Set the HandleKeyDownEvent's execution space to "Client Only".

Add the code inside the PlayActionState and HandleKeyDownEvent like below.


structChangeAvatarAnimation

Method:
    [client only]
    void PlayActionState ( string actionName, number playRate, string spriteAnimClipPlayType )
    {
        if not isvalid(self.Entity.AvatarRendererComponent) then return end

        local body = self.Entity.AvatarRendererComponent:GetBodyEntity()
        local actionEvent = ActionStateChangedEvent(actionName, actionName, playRate, spriteAnimClipPlayType)
        body:SendEvent(actionEvent)
    }


Event Handler:
    [client only] [service] (InputService)
    HandleKeyDownEvent( KeyDownEvent event )
    {
        if event.key == KeyboardKey.F then
            self:PlayActionState("swingPF", 1, SpriteAnimClipPlayType.Onetime)
        end
    }
                    

Press Play and you should now see the character do a swing animation when pressing F key.


Create a new script component "ChangeAvatarAnimation" and add it to the DefaultPlayer.

Add a OnBeginPlay method to the script.

Set the OnBeginPlay's execution Space to "Client Only".

Add the event "KeyDownEvent" to the script.

Set the HandleKeyDownEvent's execution space to "Client Only".

Add the code inside the OnBeginPlay and HandleKeyDownEvent like below.


structChangeAvatarAnimation

Method:
    [client only]
    void OnBeginPlay ( )
    {
        self.Entity.StateComponent:AddState("POLEARMSWING", PolearmSwing)
        self.Entity.StateComponent:AddCondition("POLEARMSWING", "IDLE")
    }


Event Handler:
    [client only] [service] (InputService)
    HandleKeyDownEvent( KeyDownEvent event )
    {
        local player = _UserService.LocalPlayer

        if event.key == KeyboardKey.F then
            player.StateComponent:ChangeState("POLEARMSWING")
        end
    }
                    

Create a new script statetype "PolearmSwing".

Add a boolean property "exitFlag" to the script and set it to false.

Add a OnEnter method to the script.

Add a OnConditionCheck method to the script.

Add the code inside the OnEnter and OnConditionCheck like below.


structPolearmSwing

Property:
    boolean exitFlag = false

Method:
    void OnEnter ( )
    {
        self.exitFlag = false
        _TimerService:SetTimerOnce(function() self.exitFlag = true end, 1)
        
        local player = self.ParentComponent.Entity
        if not isvalid(player.AvatarRendererComponent) then return end

        local body = player.AvatarRendererComponent:GetBodyEntity()
        local actionEvent = ActionStateChangedEvent("swingPF", "swingPF", 1, SpriteAnimClipPlayType.Onetime)
        body:SendEvent(actionEvent)
    }

    boolean OnConditionCheck ( string nextStateName )
    {
        return self.exitFlag
    }
                    

Press Play and you should now see the character do a swing animation when pressing F key.



NOTE: Almost all the default states already exist on the DefaultPlayer's AvatarStateAnimationComponent.


Here is a list of avatar action animations available:

Default

Swing
One-Handed

Swing
Two-Handed

Swing
Polearm

Stab
One-Handed

Stab
Two-Handed

Shoot

stand1

swingO1

swingT1

swingP1

stabO1

stabT1

shoot1

stand2

swingO2

swingT2

swingP2

stabO2

stabT2

shoot2

walk1

swingO3

swingT3

swingPF

stabOF

stabTF

shootF

walk2

swingOF

swingTF

alert

prone

proneStab

jump

fly

sit

ladder

rope

dead

heal

avatar