Home Tutorials Download Beta Store Forum Documentation KnowledgeBase Wiki Blog

ShiVa3D

Return to Creation

Creating Animations in Shiva - Open a door  [SOLVED]

Shaders, Level design, Sound design, Special effects

Creating Animations in Shiva - Open a door

Postby Selzier » 12 Feb 2012, 06:12

I am using the AnimBank/AnimClip editors to create a simple object translation animation in my scene. The door should take 30 frames to open, but when I play the animation in my game, the door instantly shuts and instantly opens, there is no "animation". I believe the problem is in my code but can't find the problem.

onInit:
Code: Select all
    local hObject = this.getObject ( )
   
    if ( object.hasController ( hObject, object.kControllerTypeAnimation ) )
    then
        animation.setCurrentClip            ( hObject, 0,  0 )
        animation.setPlaybackMode           ( hObject, 0,  animation.kPlaybackModeOnce )
        animation.setPlaybackLevel          ( hObject, 0,  0 )
       
        animation.setCurrentClip            ( hObject, 1,  1 )
        animation.setPlaybackMode           ( hObject, 1,  animation.kPlaybackModeOnce )
        animation.setPlaybackLevel          ( hObject, 1,  1 )
    end


onDoorClose:
Code: Select all
    local hObject = this.getObject ( )
   
    animation.setPlaybackMode  ( hObject, 1,  animation.kPlaybackModeOnce )
    animation.setPlaybackLevel ( hObject, 0,  0 )
    animation.setPlaybackLevel ( hObject, 1,  1 )
   
    animation.enablePlayback ( hObject, true )
   
    log.message ( "close" )


onDoorOpen:
Code: Select all
   local hObject = this.getObject ( )
   
    animation.setPlaybackMode  ( hObject, 0,  animation.kPlaybackModeOnce )
    animation.setPlaybackLevel ( hObject, 1, 0 )
    animation.setPlaybackLevel ( hObject, 0, 1 )
   
    animation.enablePlayback ( hObject, true )
   
    log.message ( "open" )


Any ideas how to make the animation play right?
Selzier
Platinum Boarder
Platinum Boarder
 
Posts: 502
Location: Boise

Re: Creating Animations in Shiva - Open a door

Postby Selzier » 12 Feb 2012, 16:53

I can't find any problems with my code. I don't want to "blend" any animations, I have 2 animation (1 opens the door, 1 closes the door) I want to play these 2 animations completely independent of each other, the door will either be opening or closing.

So I try telling the animation to go with a full 1 or 0 level, either opening or closing, but when the animation starts, it immediately goes to the last frame, and the door opens and closes immediately, the animation never "plays" just skips to the end.

I've tried all the playbackBeginFrame etc, but none of this helps.

Any help on how to create a simple animation in the AnimClip editor and make it play right? The clips play correctly in the AnimClip editor but I can't make the door open and close in the scene.
Selzier
Platinum Boarder
Platinum Boarder
 
Posts: 502
Location: Boise

Animation works in ModeLoop but not in ModeOnce?

Postby Selzier » 12 Feb 2012, 18:10

I noticed that if I change the PlaybackMode to Loop, it actually plays the animation BUT it loops it of course, so the door just keeps opening over and over. Is this a bug or am I doing something wrong?

animation.setPlaybackMode ( hObject, 0, animation.kPlaybackModeOnce ) :
The door INSTANTLY changes from frame 0 to frame 30 the last frame

animation.setPlaybackMode ( hObject, 0, animation.kPlaybackModeLoop ) :
The door animation actually plays correctly but looping is not desired here...

Is this a bug or how am I supposed to make the door animation play only one time?
Selzier
Platinum Boarder
Platinum Boarder
 
Posts: 502
Location: Boise

Re: Creating Animations in Shiva - Open a door  [SOLVED]

Postby Selzier » 12 Feb 2012, 18:44

Sorry for talking to myself here but I'll post the solution. Take a look at the simple code, but all I was missing was I needed to setPlaybackCursor back to 0 and the animation will play one time:

Setup the open and close animations during onInit:
Code: Select all
--------------------------------------------------------------------------------
function AI_Door.setupAnimations ( )
--------------------------------------------------------------------------------
   
    local hObject = this.getObject ( )
   
    if ( object.hasController ( hObject, object.kControllerTypeAnimation ) )
    then
        animation.setCurrentClip            ( hObject, 0,  0 )
        animation.setPlaybackMode           ( hObject, 0,  animation.kPlaybackModeOnce )
        animation.setPlaybackLevel          ( hObject, 0,  0 )

        animation.setCurrentClip            ( hObject, 1,  1 )
        animation.setPlaybackMode           ( hObject, 1,  animation.kPlaybackModeOnce )
        animation.setPlaybackLevel          ( hObject, 1,  0 )
    end
   
--------------------------------------------------------------------------------
end
--------------------------------------------------------------------------------


A custom handler to open the door:
Code: Select all
--------------------------------------------------------------------------------
function AI_Door.onDoorOpen (  )
--------------------------------------------------------------------------------
   
    local hObject = this.getObject ( )
   
    -- Open the door: set Close to 0 and Open to 1
    animation.setPlaybackLevel ( hObject, 1, 0 )
    animation.setPlaybackLevel ( hObject, 0, 1 )
   
    -- Move the Playback Cursor (position) back to 0
    animation.setPlaybackCursor ( hObject, 0, 0 )
   
--------------------------------------------------------------------------------
end
--------------------------------------------------------------------------------


And 1 more custom handler to close the door:
Code: Select all
--------------------------------------------------------------------------------
function AI_Door.onDoorClose (  )
--------------------------------------------------------------------------------
   
    local hObject = this.getObject ( )
   
    -- Close the Door: set Close to 1 and Open to 0
    animation.setPlaybackLevel ( hObject, 0, 0 )
    animation.setPlaybackLevel ( hObject, 1, 1 )
   
    -- Move the Playback Cursor (position) back to 0
    animation.setPlaybackCursor ( hObject, 1, 0 )
   
--------------------------------------------------------------------------------
end
--------------------------------------------------------------------------------
Last edited by Selzier on 12 Feb 2012, 20:14, edited 1 time in total.
Selzier
Platinum Boarder
Platinum Boarder
 
Posts: 502
Location: Boise

Re: Creating Animations in Shiva - Open a door

Postby kalango » 12 Feb 2012, 20:10

You could simply move the door by code using translateTo-like functions. The ease factor would give a nice smooth moving. I guess you must be comming from UDK right....
User avatar
kalango
Gold Boarder
Gold Boarder
 
Posts: 196
Location: Nova Scotia - Canada

Re: Creating Animations in Shiva - Open a door

Postby Selzier » 12 Feb 2012, 20:18

I've never used UDK but I did make levels for Unreal original using UnrealEd... ;)

I just have a level editor background, from ZZT to Source Engine- I don't have a very strong coding background unfortunately.. but I am working on that!
Selzier
Platinum Boarder
Platinum Boarder
 
Posts: 502
Location: Boise

Re: Creating Animations in Shiva - Open a door

Postby broozar » 07 Mar 2012, 23:14

do not use animations for stuff like opening doors. use true object translations/rotations.
User avatar
broozar
Platinum Boarder
Platinum Boarder
 
Posts: 3483
Location: Berlin - Germany


Return to Creation