Question [SOLVED] Misunderstanding v:del_animation(anim)

johnnymanly

Donator
Donator
Joined
Mar 17, 2008
Messages
55
Reaction score
23
Points
8
Location
Southwest Pennsylginia
I'm trying to use "del_animation" like this:
Code:
function clbk_poststep(simt,simdt,mjd)

if vi:get_groundcontact() == true then
    vi:del_animation(anim_Chute)
end

end
I'm expecting the animation to be deleted and the mesh groups to revert to their initial state but that's not what happens.
The animation is scaling. The chute scales up when it's supposed to but doesn't scale back down upon ground contact even though the animation is deleted.
From the docs:
Before the animation is deleted, the mesh groups associated with the animation are reset to their default (initial) positions.
Any help would be appreciated.:)
 

Thunder Chicken

Fine Threads since 2008
Donator
Joined
Mar 22, 2008
Messages
4,367
Reaction score
3,302
Points
138
Location
Massachusetts
Have you verified ground contact, and that the animation is in fact deleted?

What is the initial position for the animation? If it was initialized as fully inflated the code may be be behaving correctly.
 

johnnymanly

Donator
Donator
Joined
Mar 17, 2008
Messages
55
Reaction score
23
Points
8
Location
Southwest Pennsylginia
I verified ground contact with this:
Code:
if vi:get_groundcontact() == true then
  vi:set_animation(anim_Chute,0)
end
It works as expected.
I verified animation deletion by then calling del_animation at 300 meters. This stopped the previous code from working.
Initial position was "0", chute at small scale.
 

johnnymanly

Donator
Donator
Joined
Mar 17, 2008
Messages
55
Reaction score
23
Points
8
Location
Southwest Pennsylginia
Relevant bits...
Code:
trans_Drogue = {                          -- transformation for drogue animation
  type = 'scaling',                       -- transformation type
  mesh = 0,                               -- mesh index
  grp = {1,2},                            -- group indices
  ref = {x=0,y=0,z=0.81},                 -- reference point
  scale = {x=100,y=100,z=100}             -- scaling amount
}

trans_Chute = {                           -- transformation for chute animation
  type = 'scaling',                       -- transformation type
  mesh = 0,                               -- mesh index
  grp = {7,8},                            -- group indices
  ref = {x=0,y=0,z=0.81},                 -- reference point
  scale = {x=100,y=100,z=100}             -- scaling amount
 
 
function clbk_setclasscaps(cfg)

  -- drogue chute animation
  animcomp_Drogue = oapi.create_animationcomponent(trans_Drogue)
  anim_Drogue = vi:create_animation(0)
  vi:add_animationcomponent(anim_Drogue,0,1,animcomp_Drogue)

  -- chute animation
  animcomp_Chute = oapi.create_animationcomponent(trans_Chute)
  anim_Chute = vi:create_animation(0)
  vi:add_animationcomponent(anim_Chute,0,1,animcomp_Chute)
 
end
 

Thunder Chicken

Fine Threads since 2008
Donator
Joined
Mar 22, 2008
Messages
4,367
Reaction score
3,302
Points
138
Location
Massachusetts
Can you set the animation state to zero manually before deleting the animation?

It may be that there is something in the Lua version of the delete function that differs from the C++ API version, even though the documentation is the same.
 

johnnymanly

Donator
Donator
Joined
Mar 17, 2008
Messages
55
Reaction score
23
Points
8
Location
Southwest Pennsylginia
Easy workaround is to clear the meshes, which deletes the animations, then add the mesh again.
Code:
if vi:get_groundcontact() == true and vi:get_attachmentstatus(Attach0) == nil and vi:get_attachmentstatus(Attach1) == nil then
  vi:clear_meshes()
  vi:add_mesh('JMpl/JMpl')
end
 
Last edited:

Thunder Chicken

Fine Threads since 2008
Donator
Joined
Mar 22, 2008
Messages
4,367
Reaction score
3,302
Points
138
Location
Massachusetts
It might be a bit more efficient to just set the animation state to zero before deleting the animation:

Code:
if vi:get_groundcontact() == true then
    vi:set_animation(anim_Chute,0)
    vi:del_animation(anim_Chute)
end
 

Thunder Chicken

Fine Threads since 2008
Donator
Joined
Mar 22, 2008
Messages
4,367
Reaction score
3,302
Points
138
Location
Massachusetts
One would think so but it doesn't work.
That's odd. You can set the animation state to zero, you can delete it, but you can't do them together in the same loop?

If you have a prestep callback, you might try putting that loop in that and see if you get different behavior.
 

johnnymanly

Donator
Donator
Joined
Mar 17, 2008
Messages
55
Reaction score
23
Points
8
Location
Southwest Pennsylginia
Well actually, it works with both statements in the prestep. I should've checked that.:unsure:
Thanks for the help. It looks good so far.(y)
 

johnnymanly

Donator
Donator
Joined
Mar 17, 2008
Messages
55
Reaction score
23
Points
8
Location
Southwest Pennsylginia
Final configuration:
Code:
function clbk_prestep(simt,simdt,mjd)

  if vi:get_groundcontact() == true and vi:get_attachmentstatus(Attach0) == nil and vi:get_attachmentstatus(Attach1) == nil then
    vi:del_animation(anim_Chute)
  end

end

function clbk_poststep(simt,simdt,mjd)

  if vi:get_groundcontact() == true then
    vi:set_animation(anim_Chute,0)
  end

end
del_animation must be in prestep with set_animation in poststep.
 

Thunder Chicken

Fine Threads since 2008
Donator
Joined
Mar 22, 2008
Messages
4,367
Reaction score
3,302
Points
138
Location
Massachusetts
Final configuration:
Code:
function clbk_prestep(simt,simdt,mjd)

  if vi:get_groundcontact() == true and vi:get_attachmentstatus(Attach0) == nil and vi:get_attachmentstatus(Attach1) == nil then
    vi:del_animation(anim_Chute)
  end

end

function clbk_poststep(simt,simdt,mjd)

  if vi:get_groundcontact() == true then
    vi:set_animation(anim_Chute,0)
  end

end
del_animation must be in prestep with set_animation in poststep.
Is set_animation still required? Did you check to see if del_animation does the advertised behavior if it is in the prestep callback?
 
Top