Throwing weapons and Grenades

vp_Calvp_Cal Posts: 698Administrator, Moderator
edited December 2014 in Scripts & Mods
Please post questions and mods regarding grenades in this thread.

NOTE: Due to crunch on the multiplayer add-on, there won't initially be docs or tutorials for throwing weapons. Here is an excerpt from the 1.4.9 releasenotes regarding where to find info about how these systems work:

Grenade script
A new projectile script, 'vp_Grenade', which applies rigidbody force to a gameobject, and kills it by means of its own damagehandler after few seconds. If the damagehandler has an explosion death spawn object and the whole thing is fired from a vp_Shooter, then you have yourself a grenade! A new HD grenade model with pickups and item types included as an example. You can find it in Sky City.

Throwing weapon support
This is used for hand grenades in v1.4.9, but it could really be used to toss anything (rocks, darts, axes, knives, spears, shuriken). Two new weapon scripts, 'vp_WeaponThrower' and 'vp_FPWeaponThrower', for remote / AI and 1st person local players, respectively.

Keep in mind that this weapon type is exceedingly complex to set up (as far as UFPS is concerned, it is both a weapon and its own ammo at the same time). There is a detailed checklist of requirements at the top of the vp_WeaponThrower' and 'vp_FPWeaponThrower' scripts, so be sure to give both of those a close look.

Logically, a throwing weapon is a hidden "arm-only weapon" that is picked up along with e.g. grenade ammo. That is: a hand grenade pickup awards you both a projectile (the grenade) and a throwing weapon (typically an animated arm depicted throwing a grenade). If you already have this logical 'throwing weapon' then you won't get another one. Grenades in the form of units are kept in the inventory's internal unit bank and the throwing weapon is continually refilled with units under the hood. As soon as you throw one unit, another one pops into your hand until you're out of grenades and the 'weapon' is auto-unwielded.

There is new wielding and firing logic for thrown weapons. If AnimationType of a weapon is 'Thrown' and it is properly set up with a unitbank and ammo, the throwing weapon will be automatically 'reloaded' instantly when it is wielded. As long as there is ammo for it in the inventory, it will always have atleast one ammo ready for throwing.

NOTE: As for 3rd person, the features are in place for this to work, but the animations are placeholders. This makes tossing grenades look quite funny in 3rd person at present. You will need to find some good looking grenade throwing animations for this to look cool in 3rd person.

[ UFPS Docs ] . . . [ F.A.Q. ] . . . [ Tutorials ] . . . [ Knowledgebase ]
[ Games Showcase ] . . . [ Get it now! ]

[home] [twitter] [youtube]

Comments

  • vp_Calvp_Cal Posts: 698Administrator, Moderator
    edited December 2014
    You could make a script that throws a grenade on key press. I was planning on doing this but have had zero time for it lately =/. Something like a script / method that:
    1. backs up the id of the current weapon
    2. tries to switch to the 'grenade thrower' weapon
    3. on success, fires the 'grenade thrower' weapon once and sets a timer to switch back to the previous weapon (timed so it happens right after the throw)

    [ UFPS Docs ] . . . [ F.A.Q. ] . . . [ Tutorials ] . . . [ Knowledgebase ]
    [ Games Showcase ] . . . [ Get it now! ]

    [home] [twitter] [youtube]
  • vp_Calvp_Cal Posts: 698Administrator, Moderator
    Also, I wanted to make the throwing weapons gather force for as long as the button was pressed, and throw upon release, but alas: no time. This is something I would love to do for an upcoming version but can't say when. Perhaps someone in the forum can figure out the input code / sequence required.

    [ UFPS Docs ] . . . [ F.A.Q. ] . . . [ Tutorials ] . . . [ Knowledgebase ]
    [ Games Showcase ] . . . [ Get it now! ]

    [home] [twitter] [youtube]
  • vp_Calvp_Cal Posts: 698Administrator, Moderator
    edited December 2014
    For targets that do not use the vp_DamageHandler script (for example Shooter AI): All you have to do is deselect "require damage handler" on the explosion component (thanks, @redhawk).

    [ UFPS Docs ] . . . [ F.A.Q. ] . . . [ Tutorials ] . . . [ Knowledgebase ]
    [ Games Showcase ] . . . [ Get it now! ]

    [home] [twitter] [youtube]
  • vp_Calvp_Cal Posts: 698Administrator, Moderator
    edited December 2014
    @J_F wrote : "do the new explosions use rays that are allways checking wether they are obstructed from directly hitting the player? Or is it something more complex?"
    It raycasts (at moment of explosion) against the top and center of the bounding box of every rigidbody and UFPS player within range. You can also enable feet but it's commented out by default. We've found this to feel intuitive and work well. Basically: if you can see the grenade, it can damage you.

    If you have a lot of objects in the scene and worry about performance, then you can uncheck "AllowCover" on the explosion. I believe false is default actually.

    [ UFPS Docs ] . . . [ F.A.Q. ] . . . [ Tutorials ] . . . [ Knowledgebase ]
    [ Games Showcase ] . . . [ Get it now! ]

    [home] [twitter] [youtube]
  • PvTGreg Posts: 197Member
    can this be adapted to drop weapons on the floor? id still love to see this feature
  • genocidedolphinsgenocidedolphins Posts: 582Member, MPTester
    Grenade throwing works pretty well, but the first person animation is weak, he sort of never finishes off his throw, is this place holder too? :)
    Radiant Silver Labs - one man indie band, developing Genocide Dolphins
    Looking for an Android freelancer? Look no further: www.garethmurfin.co.uk
  • BrandSpankingNewBrandSpankingNew Posts: 2,321Member, MPTester
    Yes, I think it is kind of a place holder.

    Ya' know, I couldn't find the note on that, I'm sorry, but I do recall it being mentioned as a kind of rushed effort.

    It is here somewhere on the forum, but it would probably require a dumb-luck kind of search to find it at this point.

    I would bet (not a lot, but a little, with good odds!) that it will be improved over time as time allows.

    That throwing motion, and being able to hold the button until we release the thrown object (for the power of the throw, for example), could and should be improved, in my opinion.

    But, I stand firm in my belief that the VP crew should stay on their roadmap and let those of us "out here" solve these little niceties as they arise. (Yeah, I'm with you! Why didn't THEY think of THAT feature! ha!!)
    Beautiful objects are wrought by study through effort, but ugly things are reaped automatically without toil.
    Democritus
  • vp_Calvp_Cal Posts: 698Administrator, Moderator
    edited May 2015
    Thanks for the suggestions guys. Good stuff. The throwing system is something that I'd like to iterate before too long and dropping is a good candidate for a future UFPS version too. Just so you know it's really easy to do. I did it once for multiplayer but lost the code somehow :). It's just a matter of removing the item from the inventory and spawning a new pickup in front of the player. If it's a weapon it should be auto unwielded when it's removed from the inventory.

    [ UFPS Docs ] . . . [ F.A.Q. ] . . . [ Tutorials ] . . . [ Knowledgebase ]
    [ Games Showcase ] . . . [ Get it now! ]

    [home] [twitter] [youtube]
  • LoisGalicia Posts: 7Member
    Please Please Dont forget to update the arrow script, and making the grenade stick to shit, so we can do spears that stick in bears and things like that.
    Im a bit lost trying to make a throwable axe/spear/something that sticks to objetcs, because the arrow script seems to be outdated. I know that a basic programmer can achieve the upgrade of a simple script by himself, but im a poor designer.

    The logic is a bit confusing, because in the arrow script it seems to work like " Firing -> flying -> hitdetect (damage + stick)
    But grenade logic its like "Firing -> flying - bouncing- deathspawn(spawn explosion, or another prefab).

    I think that it will be more logical if we can select a hit effect like sticky, bounce, or something more, and after that, the deathspawn of an explosion, so this will be like "Firing - flying - stick/bounce/extrabehaviour -> deathspawn. Obviously we must be able to set the damage of the hit impack, so we can make that a hit without explosion from a sticky bomb can deal damage or not.

    Sorry for my bad grammar and writted expression.
  • genocidedolphinsgenocidedolphins Posts: 582Member, MPTester
    Awesome I adjusted the throwing to make use of molotov cocktails, dynamite etc, works really nicely..
    Radiant Silver Labs - one man indie band, developing Genocide Dolphins
    Looking for an Android freelancer? Look no further: www.garethmurfin.co.uk
  • JoseJose Posts: 16Member
    Hi, The spawn delay doesn't work in UFPS 1.5.0 and 1.5.1, I'm no programmer and I couldn't find the bug, I had to downgrade to UFPS 1.4.9 to make this work!, very annoying!
  • lucianoluciano Posts: 49Member
    Hello i ave put in player damage handler(remote) zombie character but when player die just killer player see this monster.If player 1 killl player 2 just player 1 see zombie model......no way for all players in game see enemy model?
  • JIMBOB Posts: 23Member
    Hi, I'm pretty new to UFPS and trying to make so it auto switches to Grenade and then switches back to previous weapon was using... This is what I have so far, it switches to the grenade but doesn't throw the grenade or switch back...

    Would anyone help thank you

    private vp_FPPlayerEventHandler m_player;
    private vp_FPInput Input;

    //ID of current weapon to store
    private vp_Value<int> currentWeapon;

    void Start()
    {
    m_player = FindObjectOfType<vp_FPPlayerEventHandler> ();
    Input = FindObjectOfType<vp_FPInput> ();
    }

    void Update ()
    {
    if (cInput.GetButton ("ThrowGrenade"))
    {
    //Backs up current Weapon ID
    currentWeapon = m_player.CurrentWeaponIndex;

    //Set Grenade Weapon
    m_player.SetWeapon.TryStart(1);

    //Plays Attack for Grenade
    Input.SetState ("Attack", true, false, false);

    //Sets Time to Switch back to previous Weapon
    StartCoroutine (SwitchBackGun());
    }
    }

    IEnumerator SwitchBackGun()
    {
    //How long to wait till auto switch back
    yield return new WaitForSeconds (0.5f);

    //Sets the previous weapon back
    m_player.SetWeapon.TryStart(currentWeapon);
    }
  • BrandSpankingNewBrandSpankingNew Posts: 2,321Member, MPTester
    edited December 2016
    What is cInput ... I see a reference where you are populating Input, but anyway ... you have a nice reference to the player event handler, so skip that SetState stuff and just tell your player to toss a grenade via the handler and the grenade stuff will take care of itself . m _player.Attack.TryStart(), Look at how vp_FPInput handles the attack button. I would also register my script with the event handler so that I could be notified about when OnStop_Attack is triggered and use that notification to begin my Coroutine for switching back to the previous weapon. Also, just use a regular int variable and not that vp_Value thing for your currentWeapon.


    Also, you might want to start a new thread in the future instead of keeping these old dead threads alive. They can never be marked as answered properly. Just an opinion, but I hate clutter. And besides, this is the scripts and mods section and should never have been allowed to run wild like this in the first place! Color me grumpy! haha!
    Beautiful objects are wrought by study through effort, but ugly things are reaped automatically without toil.
    Democritus
Sign In or Register to comment.