AnimationSetGroundSpeed# ( entity,alias$ )

Parameters

entity - an entity with an animation set, on itself or on one of its children

alias$ - the clip's name in the set, such as "walk"

Description

Returns how fast a clip moves its character over the ground, in metres a second.

It measures the clip's root motion: how fast the set's root motion bone travels across the ground as the clip plays, at the clip's own speed in the set and the character's scale. Move a character that fast while the clip plays and its feet don't slide, as the example's robot does. The Animation Set Editor's Measure button uses it to fill in a clip's Ground speed, which walking characters (NavWalkers) play their walk and run clips by.

It returns 0 for a clip without root motion, such as one that walks on the spot, and for a name the set doesn't have. An entity without an animation set is a runtime error.

The set's root motion mode doesn't matter: the clip is measured the same whether its root motion is extracted for your program or moves the character.

See also: PlayAnimationSet, CreateAnimationSet, ApplyAnimationSet, WalkAnimations, EntityWalkSpeed.

Example

; AnimationSetGroundSpeed Example
; -------------------------------

Graphics3D 640,480,0,2
SetBuffer BackBuffer()

camera=CreateCamera()
PositionEntity camera,0,5,-17
RotateEntity camera,12,0,0

light=CreateLight()
RotateEntity light,45,45,0

; A 20 m track, one unit to a metre: the floor's top is at y=0
floor=CreateCube()
ScaleEntity floor,10,0.25,2
PositionEntity floor,0,-0.25,0
EntityColor floor,60,80,55

; The robot's animation set: its walk and run clips have root motion
document=LoadResourceDocument("../../../samples/animation-sets/robot.animset")
If document=0 Then RuntimeError ResourceDocumentError()
library=LoadResourceDocumentAsync(document)
FreeResourceDocument document
While Not WorldReady(library)
    If WorldLoadState(library)=WORLD_LOAD_FAILED Then RuntimeError WorldLoadError(library)
    UpdateAsyncLoads 2
Wend
robot=CreateAnimationSet(FindWorldAsset(library,"resource"))
FreeWorld library
PositionEntity robot,-9,0,0
RotateEntity robot,0,-90,0

clip$="walk"
PlayAnimationSet robot,clip

While Not KeyDown(1)

    ; Space switches between walk and run
    If KeyHit(57) Then
        If clip="walk" Then clip="run" Else clip="walk"
        PlayAnimationSet robot,clip
    EndIf

    ; How fast the clip carries the robot over the ground, in metres a
    ; second: moving it that fast keeps its feet from sliding
    metres#=AnimationSetGroundSpeed(robot,clip)
    TranslateEntity robot,metres/60,0,0
    If EntityX(robot)>9 Then PositionEntity robot,-9,0,0

    ; Arrow keys move the camera
    If KeyDown(200) Then MoveEntity camera,0,0,0.1
    If KeyDown(208) Then MoveEntity camera,0,0,-0.1
    If KeyDown(203) Then TurnEntity camera,0,1,0
    If KeyDown(205) Then TurnEntity camera,0,-1,0

    UpdateWorld
    RenderWorld

    Text 0,0,"Space: walk / run   Arrow keys: move camera   Esc: exit"
    Text 0,20,"AnimationSetGroundSpeed(robot,"+Chr(34)+clip+Chr(34)+")="+metres+" m/s"
    Text 0,40,"A clip the set lacks: "+AnimationSetGroundSpeed(robot,"fly")+" m/s"

    Flip

Wend

End

Index