# General QuestionPropeller animation [solved]

#### johnnymanly

##### New member
I'd like to animate a prop in a Lua vessel.
I can set the animation like this:
Code:
pwr = vi:get_animation(anim_Prop)
da = simdt * 0.1
pwr_proc = pwr + da
gas = vi:get_thrusterlevel(thmain)

if
gas > 0
then
vi:set_animation(anim_Prop,pwr_proc)
end
but I don't know how to repeat the animation. (loop?)
Any hint would be appreciated.

Thanks.

#### Thunder Chicken

Donator
I'd like to animate a prop in a Lua vessel.
I can set the animation like this:
Code:
pwr = vi:get_animation(anim_Prop)
da = simdt * 0.1
pwr_proc = pwr + da
gas = vi:get_thrusterlevel(thmain)

if
gas > 0
then
vi:set_animation(anim_Prop,pwr_proc)
end
but I don't know how to repeat the animation. (loop?)
Any hint would be appreciated.

Thanks.
I'm assuming your animation state defines a full totation. The animation state can't exceed 1. So if it does, you have to subtract 1.

#### johnnymanly

##### New member
Do you mean I have to set the animation state back to 0 before I can make another revolution?

#### Thunder Chicken

Donator
Do you mean I have to set the animation state back to 0 before I can make another revolution?

Not quite. Remember that the animation state variable really describes what angle the propeller should be oriented at a given time on a scale from 0 to 360 degrees (0 to 1 animation state). As an example, let's say that the propeller angle increases by 62 degrees every time step. After six steps, the total angle of rotation would be 6*62 = 372 degrees. This would be equivalent to an animation state of 1.03333. You don't want to reset the state to 0 because that wouldn't give the correct angle. What you need to know is what is the angle on a 0 to 360 scale (0 to 1 animation state). So you subtract off 360 degrees (1 from your animation state) to get the proper angle of 12 degrees, at a corresponding animation state of 0.03333.

Mathematically what you want is the remainder of the sum of your animation state increments divided by 1.

#### johnnymanly

##### New member
Thanks for answering but your talking past me a bit. I assumed the angle would increase the correct amount so the animation would finish at 1. (or where I set it )

#### johnnymanly

##### New member
This seems to do it and ties rpm to thrust.
Code:
  --configuration part
anim_Prop = vi:create_animation(0)

Prop1 = {
type = 'rotation',
mesh = 0,
grp = 13,
ref = {x=0,y=0.467,z=8.928},
axis = {x=0,y=0,z=1},
}

animcomp_Prop = oapi.create_animationcomponent(Prop1)

--prop spinning part
function clbk_prestep(simt,simdt,mjd)

pwr = vi:get_thrusterlevel(thmain)
prp = vi:get_animation(anim_Prop)
da = simdt * 0.1 + (pwr * 0.1)
prp_proc = prp + da

if
prp < 1
then
vi:set_animation(anim_Prop,prp_proc)
else
vi:set_animation(anim_Prop)
end

end

#### Matias Saibene

##### Terrible developer (seriously)
This seems to do it and ties rpm to thrust.
Code:
  --configuration part
anim_Prop = vi:create_animation(0)

Prop1 = {
type = 'rotation',
mesh = 0,
grp = 13,
ref = {x=0,y=0.467,z=8.928},
axis = {x=0,y=0,z=1},
}

animcomp_Prop = oapi.create_animationcomponent(Prop1)

--prop spinning part
function clbk_prestep(simt,simdt,mjd)

pwr = vi:get_thrusterlevel(thmain)
prp = vi:get_animation(anim_Prop)
da = simdt * 0.1 + (pwr * 0.1)
prp_proc = prp + da

if
prp < 1
then
vi:set_animation(anim_Prop,prp_proc)
else
vi:set_animation(anim_Prop)
end

end
I was racking my brain all afternoon until I found this solution. Can you allow me to use it in my C++ project?
I think I know how to convert it from Lua to C++.

#### johnnymanly

##### New member
I was racking my brain all afternoon until I found this solution. Can you allow me to use it in my C++ project?
I think I know how to convert it from Lua to C++.
Of course. Feel free to use it.
If you get any weird behavior pay attention to the other comments in this thread. I'm not a very good coder.

Replies
3
Views
563
Replies
2
Views
249
Replies
0
Views
140
Replies
1
Views
401
Replies
10
Views
1K