Community Forum

Animation Script Example

Forum Overview >> Farming Simulator 2009

CategoryFarming Simulator 2009
Created17.07.2010 22:57

Jim Panousis (Jimi540) 17.07.2010 23:10
Immediately at the subject :)
I added an animation to my mod in Maya. I saved it as ForkASource

In my .xml it put this:
<forkA index="12|0" animationClip="ForkASource"/>

I read same functions at the docum... for playing the animation in the game and i made some tests with them but nothing happend.

Can you help me to put these functions to a row to play the animation?
I'm pressing a key and the animation is playing in a loop mode until i press the key again to stop.
I made some tests with the functions:

I also tried to run the getAnimCharacterSet function to the editor and it returned me zero, which means nothing? Is here some serious problem?

Best Regards,

Joshua Branson (Unknown) 18.07.2010 00:37
You also have to make the animation in the .i3d model itself. It looks something like the following:

<AnimationSet name="Your animation set name">
<Clip name="ForkASource" duration="your time duration of animation">
<Keyframes nodeId="node id of animated part">
<Keyframe time="time 1" scale="1 1 1"/>
<Keyframe time="time 2 if needed" rotation="1 1 1"/>
<Keyframe time="final time(duration)" translation="1 1 1"/>

Where it says scale,rotation and tranlation are what the animation is doing for that animation. eg. scale is scaling something, rotation is rotating something and translation is moving something on one of the three x,y or Z axes
eg, translation="x y z" rotation="x y z" scale="x y z"

Jim Panousis (Jimi540) 18.07.2010 21:43
Hi Joshua
This code is produced automated from the exporter.
I have already this code into my .i3d, but i dont know how i can use the functions in my script to make the animation to play and also to play in a loop mode. If you can help me i'll be greatfull. thanks
<AnimationSet name="character1">
<Clip name="ForkASource" duration="4958.33">
<Keyframes nodeId="30">
<Keyframe time="0" rotation="0 0 0"/>
<Keyframe time="1208.33" rotation="0 0 -43.0956"/>
<Keyframe time="2458.33" rotation="0 0 -199.472"/>
<Keyframe time="3708.33" rotation="0 0 -315.799"/>
<Keyframe time="4958.33" rotation="0 0 -360"/>

Friedrich L. (Unknown) 29.07.2010 16:25

I have not tested the code, but try with this code:

function mod:load(xmlFile)
self.time = 0;
self.entry = {};
local rootNode = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.anim#rootNode"));
self.entry.animCharSet = 0;
if rootNode ~= nil then
self.entry.animCharSet = getAnimCharacterSet(rootNode);
if self.entry.animCharSet ~= 0 then
local clip = getAnimClipIndex(self.entry.animCharSet, getXMLString(xmlFile, "vehicle.anim#animationClip"));
if clip >= 0 then
assignAnimTrackClip(self.entry.animCharSet, 0, clip);
setAnimTrackLoopState(self.entry.animCharSet, 0, false);
self.entry.animDuration = getAnimClipDuration(self.entry.animCharSet, clip);

function mod:update(dt)

if InputBinding.hasEvent(InputBinding.DoAnim) then = not;

if then
if self.time < 4958.33 then -- duration, keyTime
self.time = self.time + 10; -- keyTime = keyTime + 10
self.time = self.time;

enableAnimTrack(self.entry.animCharSet, 0);
setAnimTrackTime(self.entry.animCharSet, 0, self.time, true); -- keyTime = self.time
disableAnimTrack(self.entry.animCharSet, 0);


Thomas H. (Patar) 10.08.2010 14:31
why you don't look in an script with animations which is made from an other scripter?

Jim Panousis (Jimi540) 12.08.2010 16:05
@ Friedrich L. (Skully)

Thanks for the code. I understood how i must use these functions now.
Finally i made it. I use the code below and the animation plays perfectly.
This is loop playable animation script. Beautiful!

function MyMOD:load(xmlFile)
self.charIdA1 = Utils.indexToObject(self.rootNode, getXMLString(xmlFile, "vehicle.anim1#index"));
self.clipIndexA1 = getXMLString(xmlFile, "vehicle.anim1#animationClip");

self.something = false;

function MyMOD:update(dt)
if InputBinding.hasEvent(InputBinding.ANIMATION) then
self.something = not self.something;

if self.something then
local charIdA1 = getAnimCharacterSet(self.charIdA1);
local clipIndexA1 = getAnimClipIndex(charIdA1, self.clipIndexA1);

assignAnimTrackClip(charIdA1, 0, clipIndexA1);
setAnimTrackLoopState(charIdA1, 0, false);
setAnimTrackSpeedScale(charIdA1, 0, 3);
enableAnimTrack(charIdA1, 0);

if getAnimTrackTime(charIdA1, 0) >= getAnimClipDuration(charIdA1, clipIndexA1) then
setAnimTrackTime(charIdA1, 0, 0, true);
disableAnimTrack(charIdA1, 0);

@ Thomas H. (Patar)
Cause i don't want to copy others script and the most important is that i want every trouble i meet, to make a general post here so other beginners can see and solve their problems, as the Rotation Script Example i have post.
The only thing we want is the help from the experts ;)


Stefan Geiger - GIANTS Software 13.08.2010 08:55
You can simple call
setAnimTrackLoopState(charIdA1, 0, true);

Then the engine automatically loops the animation and you do not have to change the anim time your self.

Thomas H. (Patar) 15.08.2010 13:20
okay i know what you mean. And thanks for this post, i've already used many funktions, but never animations, but now i need them, my animation isn't an loop, so i must work with directions. I hope it will work ;)

But i don't mean to COPY something from an other script, i only mean to look wich functions you need when.

Note: Log in to post. Create a new account here.