Jump to content
Sign in to follow this  
wld427

Animat4ed barrel Recoil

Recommended Posts

Im working on the Bofors gun for project RACS. i am trying to animate the barrel to recoil when fired. below is the code i am using but i get an animation error saying im missing the source. please help.

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">class barrell1

{

type="translation"; // The type of animation.

source="reload"; // The controller that provides input.

selection="barrell1"; // The name of the skeleton bone used.

begin="slide_axis_begin";

end="slide_axis_end";

minValue=0; //The minimum value of the motion range. i.e. The controller input when animation phase is 0.

maxValue="1"; //The maximum value of the motion range. i.e. The controller input when animation phase is 1.

offset0="0";

offset1="1";

};

Share this post


Link to post
Share on other sites

the source "reload" is only valid for weapons. Is your gun configged as a weapon or vehicle?

Share this post


Link to post
Share on other sites
the source "reload" is only valid for weapons. Is your gun configged as a weapon or vehicle?

i guess that would be the issue..... its a vehicle carrying a weapon lol

Share this post


Link to post
Share on other sites

i think you have to be going the way of creating a "user" source animation and tying it to a "fired" eventhandler. Dont ask me how I havnt the slightest clue but as far as I remember thats how we used to do it in ofp.

Share this post


Link to post
Share on other sites
Hi.

You want animate a barrel like a tank one ?

Like the M1 made by Mateck ?

If that check this video at the end and tell me if that you want do.

http://mx.youtube.com/watch?v=P2gScHfIu1U

Bye.

thats exactly what i want to do

@modemaik that link is broken

Share this post


Link to post
Share on other sites

Dont use the Fired EH, thats a bad way to do it.

My released Sparviero / Hydrofoil has barrel recoil working.

Use the RELOAD animation source. The trick is to get the right values in the definitions.

In the p3d Memory LOD

Recoil_1.jpg

- Dont forget to make these point part of the "main1gun" or "OtocHlaven" definitions so they rotate with the barrel

- The barrel you want to move is defined as "main_recoil"

In the Config.cpp

Quote[/b] ]

class CfgVehicles

{

class Ship; // External class reference

class GNTXShip : Ship

{

scope=protected;

class NewTurret;

class Turrets;

class viewpilot;

class viewgunner;

class AnimationSources;

};

class gnt_Sparviero: GNTXShip

{

scope=public;

..........

..........

..........

class AnimationSources: AnimationSources

{

class gunBarrel

{

source = "reload";

weapon = GNT_76a;

};

};

In the Model.cfg

Quote[/b] ] class main_recoil

{

  type="translation";

  source="gunBarrel";

  selection="main_recoil";

  begin="recoil_start";

  end="recoil_end";

  initPhase=1;

  memory=1;

  animPeriod =.2;

  sourceAddress = "loop";

  minValue=0;

  maxValue=0.0333;

  offset0=0;

  offset1=1;

};

Now most of that is self-explainatory. the trick is MAXVALUE

In this example = 0.0333

This is calculated based on how many rounds in a weapons clip.

In this case the gun has 30 round clips therefore MAXVALUE = 1/30

Give it a whirl. Got any questions, let me know.

Edit: Updated with pic

Share this post


Link to post
Share on other sites

Well, here it's the code.

<span style='color:red'>config.cpp</span>

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">class cfgvehicles

{

class EventHandlers

{

fired = "if (_this select 1 == ""L44_120mm"") then {_this exec ""\Leo2A4\scripts\maingunrecoil.sqs""};";

};

class AnimationSources

{

class MainGunRecoil

{

type = "translation";

source = "user";

selection = "maingunrecoil";

memory = 1;

axis = "maingunrecoil";

begin = "maingunrecoil_begin";

end = "maingunrecoil_end";

minValue = 1;

maxValue = "0";

offset0 = 0;

offset1 = 0.29;

animPeriod = 0.15;

};

class maingunup

{

type = "rotationX";

source = "user";

selection = "maingunup";

memory = 1;

axis = "OsaHlavne";

sourceAddress = "clamp";

minValue = "0";

maxValue = "1";

angle0 = "rad 0";

angle1 = "rad 5";

animPeriod = 2;

};

};

};

<span style='color:red'>maingunreoil.sqs</span>

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_gun = _this select 0;

_gun animate ["maingunrecoil",1];

~0.15

_gun animate ["maingunrecoil",0];

~0.50

_gun animate ["maingunrecoil",0];

~0.15

_gun animate ["maingunup",1];

~2

_gun animate ["maingunup",0];

;_gun animate ["maingunrecoil",1];

;~0.15

;_gun animate ["maingunrecoil",0];

;~0.50

;_gun animate ["maingunrecoil",1];

exit

<span style='color:red'>model.cfg</span>

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">class cfgskeletons

{

"maingunrecoil", "OtocHlaven",

};

class cfgmodels

{

class MainGunRecoil

{

type="translation";

source="user";

selection="maingunrecoil";

memory=1;

axis="maingunrecoil";

begin="maingunrecoil_begin";

end="maingunrecoil_end";

minValue=0;

maxValue="1";

offset0=0;

offset1=0.3;

animPeriod=0.15;

};

class maingunup : otochlaven

{

type = "rotationX";

source = "user";

selection = "OtocHlaven";

memory = 1;

axis = "OsaHlavne";

sourceAddress = "clamp";

minValue = "0";

maxValue = "1";

angle0 = "rad 0";

angle1 = "rad 5";

};

};

<span style='color:blue'>L44_120mm</span> : It's the name of the main cannon in Cfgweapons

@Gnat

Can you explain me why Fired EventHandler's it's a bad choice ?

Share this post


Link to post
Share on other sites
@Gnat

Can you explain me why Fired EventHandler's it's a bad choice ?

Very simple, why run a complicated laggy script (with MP lag issues (client side view: gun fires then 1 second later u see recoil ! )) when it can all be done automatic by the game engine.

Using EventHandlers should be the last choice used.

Share this post


Link to post
Share on other sites

of course, not becasue they are bad (I think they are excellent scripts!wink_o.gif but cause the more scripts you call, the more lag you get in SP and in MP too of course smile_o.gif

Share this post


Link to post
Share on other sites
@modemaik that link is broken

No problem, fabiantronc already posted the important parts.

@all, I agree that GNats implementation ist the best way to implement this for the bofors gun.

But can we use the same implementation for multiple turrets (e.g. tanks)? I always had to use the xeh implementation, because the reload animations did not get triggered on tanks. That seems to be the cause why no ammo belt rotation works on T-72 and M1A1, although the animations are included in the BI-samples.

Share this post


Link to post
Share on other sites

gnat, did your solution and it doesn't look pretty sad_o.gif

basicly

So model is up and running with your stuff except that I am using a 8 rnd mag.

So I changed to:

maxValue=0.125; (1/8 right?)

My behaviour is:

First gun is as it should. Fire first round.

The barrel recoil, goes back to starting position and then recoil back again and stops. Next round it goes back to first position.

and repeats..

8,6,4,2 creates a "double" movement while 7,5,3,1 just make it go back once and stay there.

EDIT

Solved it, divided on twice the number in my mag. Also changed to mirror instead of loop.

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

class main_recoil

{

type="translation";

source="Barrel_Recoil";

selection="barrell1";

begin="slide_axis_begin";

end="slide_axis_end";

initPhase=0;

memory=1;

animPeriod =.2;

sourceAddress = "mirror";

minValue=0;

maxValue=0.0625;

offset0=0;

offset1=1;

};

Share this post


Link to post
Share on other sites
EDIT

Solved it, divided on twice the number in my mag. Also changed to mirror instead of loop.

hmmmm well, after more experimenting its not as simple as I suggested and as you showed GranQ.

It seems my number was a bit of a fluke!

The method you are using no doubt has a slow and even timed in-out recoil action.

With my posted example and as seem on the Hydrofoil, my Recoil has a "quick punch back" and a "slower return to extended position" .... more like true large gun recoil.

As I said, it was a fluke I got it but have since found a bit more info;

I tried to do the same with a 20 round mag and found no matter what number I used for maxValue, none looked/worked right.

I began to suspect something, and it turned out correct, but why it works I'm not sure.

You have to have an odd number magazine

Round fractions like 1/20 doesn't work, but 1/21 does.

For a 21 Round mag. a maxValue=0.0476 works just fine.

And as above, a 30 Round mag, maxValue=0.0333 works.

... obviously alright if you are not representing real magazine sizes (that are even numbers). Simple from me to change a Ships gun from 20 round mag to 21.

Hope it helps someone.

Share this post


Link to post
Share on other sites

Heres something for all u gurus to ponder:

I need to make a virtually the same animation....BUT for a rocket launcher which has a reload time of +-10 secs but the recoil should be snap in and out right after the shot lasting about 0.75 secs. So far I havnt been able to config this neither with a reload animationsource nor with a user animationsource triggered by a fired eventhandler. The reload sorta works but the anim lasts the whole 10 seconds and snaps to wrong offsets sad_o.gif

can anyone advise?

Share this post


Link to post
Share on other sites

Hi, maybe take a look at how the (OFP's) Combat team made the

animation of their Bradleys pack may help and short the find of a

solution; was very pimp and almost scary to see the barrel going

back when firing at factorys filled up of enemys. But was just a

35mm cannon that didn't spitt the shells, so it was pimp but, almost...

scary. Let's C ya

Share this post


Link to post
Share on other sites

well yeh but being an OFP addon it is surely done with "fired" eventhandler just like anything was done back then. I was merely hoping there is a way to do it through model.cfg and custom user animation controller. Anyone?

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×