Gravity Gun (called the Zero-Point Energy Field Manipulator) is implementation of gravity weapon, known for its excellent Half-Life game, for Unity.
Website
PREREQUISITES
This package for proper operation of the demo scene requires Standard Assets library from the Unity Asset Store. Import the following packages from the standard asset library into your project: - Characters - Prototyping
The described package helps to create various types of weapons, whose operation consists in leveling the gravitational force for objects under the action of this weapon.
The weapon allows you to pull and lift heavy objects and throw them into space.
The main part of the package consists of two scripts: GravityGun.cs and WeaponInput.cs. The GravityGun.cs script contains the entire implementation of gravity weapon. It contains algorithms for attracting objects, keeping them in front of the barrel of the weapon, launching them into space and for firing a laser beam into objects on the scene. In contrast, the WeaponInput.cs script is a base class for creating an interface between the weapon and the input system used in a specific project.
The GravityGun.cs script uses the Unity physics system. Works only with objects that have the Rigidbody component assigned.
The main component allows you to set the parameters for attracting objects, parameters of the point that holds the object in front of the barrel of the weapon, shooting parameters and audio clips played in the right situations.
Parameter [Aim Camera] is used to determine the point on the object in which the observer is pointing the weapon. In most projects it will be the main camera in the scene. In typical FPP games, the weapon is located at some distance (right or left) from the axis of the camera through which the world is observed. Depending on the distance of the point at which the camera is pointing the direction of the weapon must be properly adjusted - so that the weapon points the same point in space as the camera. Otherwise, the shots from the weapon would go past the point in which the player points
Parameter [Attraction Layer Mask] can be used to filter types of objects that are subject to the action of gravity weapons. Here you can set the layer mask on which the weapon will work. All objects that will belong to other layers than indicated in this parameter - will not be attracted by the weapon.
The [Holding Point] and [Holding Radius] parameters determine the location of the holding zone. If a given object, when attracted by a weapon, hits this zone, it will be trapped until it is released by the weapon operator. The zone should be set so that larger objects that reach it do not interfere with the weapon model.
Parameter [Shooting Charge Time] determines how long the weapon reloads after the shot. If audio clips are used when shooting and reloading weapons, this parameter should be set so that the reload time is not shorter than the playback time of the both audio clips.
Parameter [Ray Cast Radius] is a more technical parameter. Specifies the radius (half the width) of the raycast beam that attracts objects, which affects the accuracy of aiming. Smaller values of the parameter increase the accuracy of aiming, but make it difficult to hit smaller and more distant objects, in which you have to aim very precisely. Larger values of the parameter reduce the accuracy of aiming - then it is easier to hit small objects, but the chance of incorrect hits, especially large and close objects, increases.
Weapon Input component works by pulling information about the status of primary and secondary action (shooting / attraction) from the input system. This is the base class from which you have to inherit your own class implementing a specific input system.