cassius Posted May 20, 2016 Share Posted May 20, 2016 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; } Quote 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 More sharing options...
martyj Posted May 20, 2016 Share Posted May 20, 2016 gun.frame is never reset to 1 in this code. You should probably reset it in this statement if (gun.frame >= gun.animlength) { idle = true; done = true; // here } Quote Link to comment Share on other sites More sharing options...
cassius Posted May 20, 2016 Author Share Posted May 20, 2016 Thanks for reply. I will do it later. Quote 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 More sharing options...
cassius Posted May 20, 2016 Author Share Posted May 20, 2016 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. Quote 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 More sharing options...
cassius Posted May 20, 2016 Author Share Posted May 20, 2016 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. Quote 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 More sharing options...
macklebee Posted May 20, 2016 Share Posted May 20, 2016 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 Quote 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 More sharing options...
cassius Posted May 21, 2016 Author Share Posted May 21, 2016 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. Quote 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 More sharing options...
cassius Posted May 21, 2016 Author Share Posted May 21, 2016 Got it working. Thanks everyone for your help. Quote 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 More sharing options...
Recommended Posts
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.