Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Studio Chat / Play an object-animation without hitting a key

Author
Message
guegra
4
Years of Service
User Offline
Joined: 9th Jan 2020
Location:
Posted: 15th Nov 2021 15:36
I made a Character (he is called frieder) in Blender and exported it to AppGameKit as an fbx-file. The file has a lot of animations in it, e. g. walking, standing and looking around. My character walks from the left side of the screen to the right. This works. I wanted him to stop at a certain point and play another animation.
Therefore I wrote the following code:

function bewegen ()
if GetObjectX(frieder)<4
MoveObjectLocalZ (frieder, -0.1)
elseif GetObjectX(frieder)>4
PlayObjectAnimation( frieder, handlung[13], 0, 40, 0, 1 )
endif
endfunction

The Character stops and there is a little animation to the first frame of the animation that should be played.

if I write

function bewegen ()
if GetObjectX(frieder)<4
MoveObjectLocalZ (frieder, -0.1)
elseif GetObjectX(frieder)>4
if ( GetRawKeyPressed( 35 ) )
PlayObjectAnimation( frieder, handlung[13], 0, 40, 0, 1 )
endif
endif
endfunction

the animation 'handlung[13]' is played when I hit the key ('end').
Is there a possibility to go from one animation to another withour hitting a key or a mouseclick???

Attachments

Login to view attachments
Game_Code_here
3
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 15th Nov 2021 16:29
if ( GetRawKeyPressed( 35 ) )
PlayObjectAnimation( frieder, handlung[13], 0, 40, 0, 1 )
endif

Is a ending flag

So do this

If getspriteplaying(frieder)=0 then playsprite(frieder)
ando
4
Years of Service
User Offline
Joined: 21st Feb 2020
Location: Australia
Posted: 15th Nov 2021 16:59 Edited at: 15th Nov 2021 17:14
Also looks like you are checking less than 4 and greater than 4. What if it = 4 ?

BASIC appeared in May 1964. Lightning flashed, the wind roared and the Earth moved.
And nine months later I was born.
So here I am.
I am Basic.
Code is in my genes.
Game_Code_here
3
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 15th Nov 2021 17:29


Sorry I see you are using objects not sprites.



ando
4
Years of Service
User Offline
Joined: 21st Feb 2020
Location: Australia
Posted: 15th Nov 2021 17:31 Edited at: 15th Nov 2021 17:49
Test all the frames too.
PlayObjectAnimation( frieder, handlung[13], 0,last frame number, 1, 1 ) // changed to 1 for repeat
print(" "+str(GetObjectAnimationTime(frieder)))
BASIC appeared in May 1964. Lightning flashed, the wind roared and the Earth moved.
And nine months later I was born.
So here I am.
I am Basic.
Code is in my genes.
ando
4
Years of Service
User Offline
Joined: 21st Feb 2020
Location: Australia
Posted: 15th Nov 2021 18:26 Edited at: 15th Nov 2021 19:18
You are constantly telling it to play from frame 0 so it can't reach frame 1 2 3 etc

@ Game_Code_here. It took me a while to see that one and now I see how your response is correct. (if the animation is stopped at the end of the walk)
I'll just go back to sleep.
BASIC appeared in May 1964. Lightning flashed, the wind roared and the Earth moved.
And nine months later I was born.
So here I am.
I am Basic.
Code is in my genes.
ando
4
Years of Service
User Offline
Joined: 21st Feb 2020
Location: Australia
Posted: 15th Nov 2021 19:42
You could avoid stopping the animation like this.
Where you tell your anim to walk add this-
anim_mode$="walk"
and add an anim_mode$ name for every animation.

then


I used this code as a test.


BASIC appeared in May 1964. Lightning flashed, the wind roared and the Earth moved.
And nine months later I was born.
So here I am.
I am Basic.
Code is in my genes.
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 15th Nov 2021 20:57
To "auto skip" to an animation without no user input you will need to get the animation time v's duration, if time=duration its the last frame, play the next ani ...

or use GetObjectIsAnimating, if the previous animation was looped then this will always be true so use time v's duration instead

setting up animations like this you are 1000% going to need to use a a very strict "state machine"
Open Source plugins
Cl - DnD Plugin
Buy Me A Coffee

Login to post a reply

Server time is: 2024-04-26 02:26:08
Your offset time is: 2024-04-26 02:26:08