Jump to content

reload animation


cassius
 Share

Recommended Posts

 

I wrote the function below [ in c++] to reload a gun which before had been in idling anim mode.The problem is it works great but ONLY ONCE. If I press R key after first time it does not respond;

Can anyone help?

 

frame = 0 at start. animlenght is 53.

 

 

void reload_gun()

{

if (gun.frame < gun.animlength)

{

gun.model->SetAnimationFrame(gun.frame, 1, gun.seq);

gun.frame = gun.frame + 1.0;

}

if (gun.frame >= gun.animlength)

{

idle = true;

done = true;

}

amd quad core 4 ghz / geforce 660 ti 2gb / win 10

Blender,gimp,silo2,ac3d,,audacity,Hexagon / using c++

Link to comment
Share on other sites

if I hold down the R key the animation now works but I feel I should be using KeyHit not Keydown but that does nothing. With KeyDown the anim stops unfinished when I let go the key.if I keep pressing R it repeats until I let go.

amd quad core 4 ghz / geforce 660 ti 2gb / win 10

Blender,gimp,silo2,ac3d,,audacity,Hexagon / using c++

Link to comment
Share on other sites

How to make a one shot animation that works once. Can anyone show me? Thanks.s

 

Is it possible to use KeyHit to trigger an animation.

 

I am getting nowhere with this.

amd quad core 4 ghz / geforce 660 ti 2gb / win 10

Blender,gimp,silo2,ac3d,,audacity,Hexagon / using c++

Link to comment
Share on other sites

I would suggest looking over the inherent scripts as they are already created to show how to perform one shots, looping, blending animations between each other, etc... The FPSGun.lua script (along with the AnimationManager script) performs everything you are asking.

 

But a simple example of a one-shot animation not taking into account blending:

window = Window:Create("Example", 0, 0, 800, 600, 17)

context = Context:Create(window)

world = World:Create()

camera = Camera:Create()

camera:SetPosition(0,.8,-1.2)

light = DirectionalLight:Create()

light:SetRotation(35,35,0)

 

player = Model:Load("Models/characters/crawler/crawler.mdl")

frame = 0

blend = 1.0

sequence = "Idle"

recursive = true

oneshotdone = true

 

while not window:KeyHit(Key.Escape) do

if window:Closed() then return false end

 

if window:KeyHit(Key.Left) and oneshotdone==true then

sequence = "Attack1"

frame = 0

oneshotdone = false

end

if window:KeyHit(Key.Right) and oneshotdone==true then

sequence = "Attack2"

frame = 0

oneshotdone = false

end

 

player:SetAnimationFrame(frame,blend,sequence,recursive)

frame = frame + Time:GetSpeed()

if frame>=player:GetAnimationLength(sequence) then

sequence = "Idle"

frame = 0

oneshotdone = true

end

 

Time:Update()

world:Update()

world:Render()

context:SetBlendMode(Blend.Alpha)

context:DrawText("Press Left/Right Arrow Keys",2,2)

context:SetBlendMode(Blend.Solid)

context:Sync(true)

end

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

Thanks mack. My own one shot routine is taken from my other game and works ok when a character is killed. I am trying to adapt it to reloading a gun, but it does not work from a Keydown or a KeyHit so I am trying to make it a little remote or indirect from those.

amd quad core 4 ghz / geforce 660 ti 2gb / win 10

Blender,gimp,silo2,ac3d,,audacity,Hexagon / using c++

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...