Page 1 of 2
Gatling gun code
Posted: 19 Aug 2007, 07:51
by Pressure Line
I'm sure someone else will find this useful. I was trying to make the animation for a gatling gun type weapon, and this is what i came up with.
Code: Select all
FirePrimary()
{
emit-sfx 1024 from flare1;
turn barrel to z-axis <90.000000> speed <450.000000>;
sleep 200;
turn barrel to z-axis <0.000000> now;
}
the weapon this unit uses is a single shot weapon, with a reload time of 0.2 seconds.
heres a little animation (i know its terrible and i should just upload a video somewhere but meh)
ps, make sure you have "smoothanim=0;" set in the unit.fbi or lulz will result.
*edit* i forgot to mention, that even though this gun has 4 'barrels' it only has one flare, the flare is attached to the part of the unit that provides the x-axis rotation
Posted: 19 Aug 2007, 07:52
by Peet
oooorrrrr leave smoothanim on so that it doesnt look like crap at low speeds, and use a wait-for-turn instead of a sleep.
Posted: 19 Aug 2007, 08:03
by Pressure Line
thought id better add in the formulae for determining the angle and speed of the rotation.
for the angle:
simply divide 360 by number of barrels, in this case:
for the speed of rotation:
for this we need the reload time of the weapon, for my machine gun, its 0.2s or 200ms. now we can determine how many times a second the gun will fire, so for my mg, its 5.
now we multiply the angle of rotation by the number we just got out of our calculator
Posted: 19 Aug 2007, 08:07
by Pressure Line
Peet wrote:oooorrrrr leave smoothanim on so that it doesnt look like crap at low speeds, and use a wait-for-turn instead of a sleep.
that wont work with the "turn barrel to z-axis <0.000000> now" because the barrel wont instasnap back to the start position with smoothanim activated.
Posted: 19 Aug 2007, 08:18
by Peet
Mine works with smoothanim on o_O
Posted: 19 Aug 2007, 08:23
by Argh
SmoothAnim is appallingly inefficient, and it screws up animations done correctly. It is only worth using for crappy animations done with TURN-NOW / MOVE-NOW. Which are, by definition, crappy, because you can save bazillions of lines of instruction if you actually know what you're doing.
However, instead of using TURN at all, in this particular case, what PL should use is:
Code: Select all
#define MY_KEWL_MUZZLEFLASH 1024
AimWeapon1()
{
//Do aiming animations, blah blah blah, also do this part
play-sound (MY_KEWL_SPINUP_SOUND_FX,5);
spin barrel around z-axis speed <450> accelerate <100>;
}
FireWeapon1()
{
emit-sfx MY_KEWL_MUZZLEFLASH from flare1;
sleep 200;
}
Then, during RestoreAfterDelay:
Code: Select all
RestoreAfterDelay(RandomSeed)
{
RandomSeed = RAND(1000, 2000);
sleep RandomSeed;
//start restoring Piece positions back to default, blah, blah
play-sound (MY_KEWL_SPINDOWN_SOUND_FX,5);
spin barrel around z-axis speed <350>;
sleep 500;
spin barrel around z-axis speed <250>;
sleep 500;
spin barrel around z-axis speed <150>;
sleep 500;
spin barrel around z-axis speed <50>;
sleep 500;
stop-spin barrel around z-axis;
}
Reasons for doing it this way:
1. It makes an awesome noise when spinning up and down, like a minigun.
2. It uses SPIN, instead of some lame TURN / TURN-NOW stuff, and spins down over time, naturally, instead of coming to a halt immediately. Since I did not use a SIGNAL command, RestoreAfterDelay can be interrupted, at any time, by AimWeapon1(). Important, to avoid glitches (I really don't see the point of SIG_RESTORE, frankly, there are better ways to achieve the same purpose).
3. It leaves the minigun barrels in slightly random positions, which is cooler-looking. If you have attached the emitting Piece to the rotating barrels, it changes the position of emission- if you want to simulate a true Gatling, which has a fixed chamber and rotating barrels, attach the Piece to the Piece that changes the x-axis of the gun, not the barrels.
Oh, and the #define line is there to save your brain- much easier to go from the Unit's FBI to the COB to the CustomExplosionGenerator if you're consistent at all times about the name, and will save you a lot of time debugging.
Posted: 19 Aug 2007, 08:26
by smoth
does any one even play gundam?

Posted: 19 Aug 2007, 08:41
by Argh
Lolz! And, um, what Smoth is kindly trying to tell you, PL, is that now that you're starting to get the hang of basic scripting, you might want to study his vast code repository in Gundam, which is fairly well-commented code, IIRC.
Posted: 19 Aug 2007, 09:08
by Pressure Line
Argh wrote:3. It leaves the minigun barrels in slightly random positions, which is cooler-looking. If you have attached the emitting Piece to the rotating barrels, it changes the position of emission- if you want to simulate a true Gatling, which has a fixed chamber and rotating barrels, attach the Piece to the Piece that changes the x-axis of the gun, not the barrels.
*edit* i forgot to mention, that even though this gun has 4 'barrels' it only has one flare, the flare is attached to the part of the unit that provides the x-axis rotation
said this before you posted argh
the reasons i did it the way i did:
1: damn easy
2: i wanted the fire to happen when the barrel was at the point where it would be lined up with the chamber inside the sleeve
Posted: 19 Aug 2007, 09:30
by Argh
Reasons not to do it that way:
1. Unless the minigun is giant, nobody will ever check the barrel rotations vs. the chamber. Really.
2. It's just as easy to spin it, and it allows you to make the restore cooler, too, with few lines of code. Are you really arguing that you're too lazy to write a few more lines? Gimme a break, dude.
3. Turn NOW is not really instant. There will be a slightly-noticeable visual flicker as it turns back, because it does not actually turn instantly- Spring's code actually makes it turn. This "NOW is not really NOW" problem is why, when I did the Knight with rotating, animated tracks (old version of NanoBlobs), had to show the tracks before hiding the previous ones- kind've annoying, really, but it's the way it goes. If you really, really, really must do this the precise way, here's how to code it, anyhow:
Code: Select all
FirePrimary(Loop)
{
emit-sfx MY_KEWL_FLARE from flare1;
Loop = Loop + 1;
If (Loop == 5)
{
Loop = 1;
}
If(Loop == 1)
{
turn barrel to z-axis <90> speed <450>;
}
If(Loop == 2)
{
turn barrel to z-axis <180> speed <450>;
}
If(Loop == 3)
{
turn barrel to z-axis <270> speed <450>;
}
If(Loop == 4)
{
turn barrel to z-axis <270> speed <450>;
}
}
Now it's 100% precise. But my way is faster, and will look as good. Note that I didn't even bother with a sleep. Know why? Because, if your weapon's ReloadTime is 0.2 or higher... er, the barrel will have already reached the appropriate position first- that's how timing works. No need to sleep.
4. Just because it's damn easy doesn't mean you didn't just get a better, cooler way for free, mister.
Posted: 19 Aug 2007, 09:46
by BlackLiger
Off topic: Pressure... dude.... you're making a battlezone 1 mod for spring? Epic!!
On topic: W00t.... gattling guns. Thanks! this might be useful :)
Posted: 19 Aug 2007, 09:56
by Pressure Line
BlackLiger wrote:Off topic: Pressure... dude.... you're making a battlezone 1 mod for spring? Epic!!
On topic: W00t.... gattling guns. Thanks! this might be useful :)
off topic: yes, but ive vowed never to release anything on this board
on topic: i find it interesting that as soon as i post a script fragment up here, it gets swarmed all over and suggestions come flying out of everywhere... yet when i was writing the script 2 weeks ago i couldnt find anything particularly useful (i dont have gundam)
Posted: 19 Aug 2007, 10:06
by smoth
then what is this thread? posting code? that is a release to the community.
Look man, there is no reason to go all emo, if you went through have the crap I have you would have quit with your current attitude. Honestly, you have not even begun to felt the bullshit this community can dump on you. My advice is to do what you want and stop bothering with battlezone's content.
did you know microsoft made mechcommander 2 opensource? that means it is open to a spring port!
Posted: 19 Aug 2007, 10:16
by Pressure Line
how bout i do whatever the hell i want?
*edit* and fine. if people want me to stop posting snippets like this, i'll come back when there is a community worth working for/with.
Posted: 19 Aug 2007, 10:21
by smoth
exactly what I am talking about, this community is "worth working with" I hate to tell you but there are many very talented people in this community that ARE worth working with.
seriously, is this how you handle all mildly negative discussion?
Posted: 19 Aug 2007, 10:24
by Pressure Line
smoth wrote:exactly what I am talking about, this community is "worth working with" I hate to tell you but there are many very talented people in this community that ARE worth working with.
seriously, is this how you handle all mildly negative discussion?
oh, im quite aware of that and work quite well with some parts of the Spring community, forums just bring out the worst in people (lol 4chan?)
Posted: 19 Aug 2007, 10:33
by smoth
MOST forums will bring out the worst in people. IRL I can punch a troll, on the internet I cannot. Believe me I wish I could. However, if you quit because of them then what are you left with? You let some probably preteen jackoff get in your way?
Nah, you keep going. When the heat of this forum(something you have only seen a wiffle of) was all on me for some reason, I merely retreated to my own site but never stopped gundam despite all the bullshit I had received.
Now the battlezone stuff, personally I don't care as long as you tell people that you are not really making a mod. People will actually want it unless you tell them the truth of it. I don't care what sort of file rips you do on your machine, hell I thought about putting shogo:mad in spring once. However, why bother with battlezone? you can better invest your time in actually releasable content. That is the part that bothers me, someone wasting time posting shots of something they know they should not release and cannot release. I think you should have kept working on your project and you probably would have learned a lot by now.
Posted: 19 Aug 2007, 11:01
by Pressure Line
modeling wise, with UP, ive hit a wall, i literally cannot think of how to do the remaining units.
im starting up something new, and i will figure out how to texture properly while im at it. realistically, i havent done a whole lot with BZ except build and refine code, as well as fumble around with weapons and a little bit of ceg
Posted: 19 Aug 2007, 11:05
by KDR_11k
FireWeaponX() {
signal SIG_Fire;
set-signal-mask SIG_Fire;
emit-sfx 1024 from flare;
spin barrel around z-axis speed <3600> acceleration <999999>;
sleep 30;
stop-spin barrel around z-axis deceleration <720>;
}
Or something like that. It's how FPses handle gatlings I think. Remember that vulcans, miniguns, etc were designed to reach firerates of about 100 rounds per second which is faster than your script gets called anyway.
Posted: 19 Aug 2007, 11:07
by smoth
well, what units are you having trouble with? why not just post ideas or general concepts and let people brainstorm with you. Sometimes when in a jam it is good to bounce ideas off of people even some times they throw out absolute stupid or brilliant ideas.