The Trajectory Object is the base component for any object that is projected from the character.This can include a wide range of objects including rockets, arrows, grenades, or shells. If the Trajectory component is added directly to the character then it can also show a trajectory curve of the direction that the object will follow.
Visible Trajectory Curve Setup
The Trajectory Object component can optionally display a curve indicating where the object is going to move towards when launched. This is a deterministic curve so the path will be accurate for where the object lands. This curve can also be used within VR to show the location that the first person player is going to teleport to.
- Select the GameObject that you want the curve to affect. For our example we selected the Nolan/Items/PrimaryFragGrenade GameObject since this curve should be displayed by the ThrowableItem.
- Add the following components:
- Trajectory Object
- Line Renderer
- Capsule Collider. This component is optional and can be nothing, a Capsule Collider, or Sphere Collider.This component will tell the Trajectory Object what type of collisions to use (if no collider is added a standard raycast is used). The Capsule Collider was chosen for this example because the frag grenade uses a Capsule Collider.
- The Trajectory Object values should match the values of the Trajectory Object that is being used. For this example all of the default Trajectory Object values can be left alone.
- The following Line Renderer values should be changed:
- Cast Shadows: Off
- Receive Shadows: Disabled
- Materials: your Line Renderer material
- Positions: 0
- Width: 0.15
- The Capsule Collider values should match the Capsule Collider values on the object being used (the frag grenade):
- The final step is to enable the trajectory upon aim with the frag grenade.This can be found under the Trajectory foldout of the ThrowableItem component:
Initialize On Enable
Should the component initialize when enabled?
The mass of the object. The mass affects the velocity, the larger the mass the less the velocity.
Start Velocity Multiplier
A multiplier to apply to the starting velocity.This is useful for simulation when the trajectory curve should account for any velocity that is added to the character when the object is being thrown.
The amount of gravity to apply to the object. The gravity direction is determined by the character’s up direction.
The movement speed of the object. This value is multiplied by the velocity to give the final new position.A larger speed value is most useful if the trajectory curve is visible to reduce the number of total positions.
The rotation speed of the object. This value is slerped between the original rotation and the target rotation.
The damping value to apply to the movement.The higher the damping the quicker the object will stop moving.
The damping value to apply to the rotation. The higher the damping the quicker the object will stop rotating.
Rotate In Move Direction
Should the object rotate in the direction that the object is moving? This is useful for a bow and arrow where the arrow should face in the movement direction.
When the velocity and torque have a square magnitude have a square magnitude value less than the specified value then the object will be considered settled.Settled objects do not update anymore and will not move/rotate.Set to 0 if the object should never settle.
Sideways Settle Threshold
Specifies if the collider should settle on its side or upright.The higher the value the more likely the collider will settle on its side. This is only used for CapsuleColliders and BoxColliders. This is useful for bullet shells when you want them to land upright.
Start Sideways Velocity Magnitude
Starts to rotate to the settle rotation when the velocity magnitude is less than the specified values.
The layers that the object can collide with.
The identifier that is used when the object collides with another object. If the identifier is null it can be overridden by the object initializing the trajectory object.
When a force is applied the multiplier will modify the magnitude of the force.
Specifies how the object should behave after hitting another collider.
- Collide: Collides with the object. Does not bounce.
- Reflect: Reflect according to the velocity.
- Random Reflect: Reflect in a random direction. This mode will make the object nondeterministic but for visual only objects such as shells this is preferred.
- Ignore: Passes through the object. A collision is reported.
Specifies the multiplier to apply to the reflectvelocity (if the object can reflect).
Max Collision Count
The maximum number of objects that the projectile can collide with at a time.
Max Position Count
The maximum number of positions any single curve amplitude can contain.This is only used when the curve is being displayed.