Search Unity

Human shields and throwing things in an FPS

Discussion in 'Game Design' started by Not_Sure, Jul 14, 2022.

  1. Not_Sure

    Not_Sure

    Joined:
    Dec 13, 2011
    Posts:
    3,546
    Does anyone know of some good references, tutorials, or examples of implementing picking up large items in an FPS?

    For some background in my FPS I will have a permanent grappling beam accessible to the player at all times.

    It can work like a grappling hook like in Titan fall or Halo infinite with objects larger than the player, a gravity gun like in Half-life 2 for objects smaller than the player, and a combination of the two where the player and the object move towards one another and the player’s movement speed in greatly reduced when they are holding it.

    So as an example they could pick up a brick and shoot it without effecting the player movement at all. Or they could grab onto a large crate to fling themselves up to an out of reach area. Or they could grab an enemy soldier and hold them by the throat in front of them while using them as a human shield.

    So I suppose the issues I’m having is how should I do this?

    Im not crazy about how half-life 2 just keeps moving the to a point (all the while jittering and making a terrible racket).

    I would prefer the items and soldiers to snap to the player and act as part of the screen UI, allowing the player to turn freely as though they were not there, but still act as a shield.

    and of course throw them.

    I have some ideas about how to do this, but it seems overly complicated and would require tons of layers.

    Does anyone have any suggestions?
     
  2. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,620
    Deus Ex has picking up large items. Ghost Recon: The New Ones have grabbing people.

    Snapping to the player should be pretty easy. Have an anchor point which is a child of the player's GO, and once it's arrived just move the target object to that anchor position each frame after the player's position is updated. To adjust where an object sits, move the anchor point. You can have different anchor points for different types of objects, or grabbable objects can have their own anchors for that purpose.

    If they're rigidbodies I'd suggest making them kinematic once they're attached, assuming that by "part of the screen UI" you mean "they don't move at all as if they were UI elements", but that's just a guess. Personally, giving them a little elasticity and momentum sounds like it'd feel better.

    What's your idea that requires tons of layers, and what are they for?
     
  3. BIGTIMEMASTER

    BIGTIMEMASTER

    Joined:
    Jun 1, 2017
    Posts:
    5,181
    You need a location to snap targeted object to, that location needs to be child of character, and you probably want to query the target object to find out how it should be interacted with.
    Like does it snap to player or does player snap to it.

    I just do the simplest parts first. Easy to add lerp and animations once the basic communications are in place.

    for query the target object probably easiest way is just add some tags. If it’s for tag “big grabbable item” then you can do fling the player, if tag “small grabbable item” then grab the object.
    May also be a component which contains the behavior in which case you just need reference to the player controlled game object.

    I think in general if you can kee different behaviors separated into distinct classes or components that will make the code more manageable. So when you want to work on throw object that is all in one place, and fling character towards target they is one place. Trying to avoid many if/else conditionals makes life easier for me.