playMaker

Author Topic: Ammo count , Recoil system and Fire rate system.  (Read 6329 times)

PikabobAlex

  • Playmaker Newbie
  • *
  • Posts: 22
Ammo count , Recoil system and Fire rate system.
« on: December 17, 2012, 11:31:03 AM »
Hi , my English is not very well, so sorry about that. Such a shame for me..:/

I'm working with my own project, and I tried to make a Gun Script. But I have no idea how it's work. Any expert here can teach me?  please and thanks...


Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3987
  • Official Playmaker Support
    • LinkedIn
Re: Ammo count , Recoil system and Fire rate system.
« Reply #1 on: December 19, 2012, 11:10:34 AM »
The ThrowGrenade sample scene might also be a good starting point:
PlayMakerSamples/TestLab/Physics/ThrowGrenade


PikabobAlex

  • Playmaker Newbie
  • *
  • Posts: 22
Re: Ammo count , Recoil system and Fire rate system.
« Reply #2 on: December 20, 2012, 11:44:54 AM »
The FireRate and Ammocount was solved...
But now the problem is recoil system.
I checked on unity forums about the recoil system like this....
Code: [Select]
ar curRecoil : float;

var maxRecoil : float;

var recoilAmount : float;

var startingRotation : float;

var recoveryModifier : float;

 

var gun : Transform;

 

function Fire()

{

   // Shoot stuff at stuff

   if (maxRecoil > curRecoil) {

      gun.localEulerAngles.x -= recoilAmount * Time.deltaTime;

      curRecoil += recoilAmount * Time.deltaTime;

   }

}

 

function Update()

{

   // Other stuff

   if (curRecoil > 0) {

      curRecoil -= recoveryModifier * recoilAmount * Time.deltaTime;

      gun.localEulerAngles.x += recoveryModifier * recoilAmount * Time.deltaTime;

      if (curRecoil < 0) {

         gun.localEulerAngles.x = startingRotation;

         curRecoil = 0;

But i can't find a action similar like this...
Any ideas? guys?

Red

  • Hero Member
  • *****
  • Posts: 563
Re: Ammo count , Recoil system and Fire rate system.
« Reply #3 on: December 20, 2012, 06:20:45 PM »
though i'm not a good programmer by any means (which is why i went with PM) it looks like you're trying to add a cool-down for your gun... is that correct? (as in, a short span of time where the player would have to wait for them to be able to fire the gun again?)

if not that, could you explain a bit more what sort of behavior you're looking for? "recoil" could mean a couple different things which would need different approaches to solving them.

PikabobAlex

  • Playmaker Newbie
  • *
  • Posts: 22
Re: Ammo count , Recoil system and Fire rate system.
« Reply #4 on: December 20, 2012, 11:22:28 PM »
I want after i finish shooting than the crosshair will slowly go back to original position...
But the "slowly", I have no idea how to make that...

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Ammo count , Recoil system and Fire rate system.
« Reply #5 on: December 24, 2012, 03:19:40 AM »
Hi,

 What is your crosshair made of? is it a gameObject or a guitexture?

 you can always use iTween quite simply. When the fire has finished, you simply use iTween to move your crossHair to a certain position. when the user fire again, you simply "stop" the itween.

 Have you tried that?

bye,

 Jean

PikabobAlex

  • Playmaker Newbie
  • *
  • Posts: 22
Re: Ammo count , Recoil system and Fire rate system.
« Reply #6 on: December 26, 2012, 10:44:18 AM »
It 's a game object...
I've done the Ammo count and Fire rate so far.
But now the Recoil system have blow my head off... :-[
I've tried using Random Float, and set it to Set Rotate or Rotate on X and Y axis
But it's not working at all for me.
I want the first shot is more accurate than second shot.

PikabobAlex

  • Playmaker Newbie
  • *
  • Posts: 22
Re: Ammo count , Recoil system and Fire rate system.
« Reply #7 on: December 26, 2012, 11:02:24 AM »
though i'm not a good programmer by any means (which is why i went with PM) it looks like you're trying to add a cool-down for your gun... is that correct? (as in, a short span of time where the player would have to wait for them to be able to fire the gun again?)

if not that, could you explain a bit more what sort of behavior you're looking for? "recoil" could mean a couple different things which would need different approaches to solving them.

Yeah, I even not a programmer. Cool down? Em...not very i think. Cool down I can handle that with PM, but Recoil.
The Recoil I said is Accuracy of Gun.
I have no idea how it's work in game.
I thought just add the Random Int/Float Value to X and Y axis.

kiriri

  • Hero Member
  • *****
  • Posts: 506
Re: Ammo count , Recoil system and Fire rate system.
« Reply #8 on: December 26, 2012, 12:55:04 PM »
in my own fps project I use an empty which is parented to the gun. On mouse button down, I set the rotation of the empty to that of the gun + a random low value vector. This makes the weapon slightly inaccurate if I then do the raycast from the empty.

Then once the raycast is done (the first bullet is off) I rotate the weapon by say 5 degrees on the x axis (for me). I have a secondary FSM which then smoothly tries to interpolate the rotation back to 0/0/0 .
After that shot is done, and if the mouse button is still down, the next shot will go slightly up, because the secondary FSM didn't rotate the weapon fast enough to get back to 0/0/0 . Based on the current rotation the inaccuracy of my weapon also changes, so that you won't only shoot up but your individual bulletholes will also be farther apart.

Did that help?
Best,
Sven