🏹Aim
1.4.2.d+
Overview
The Aim Component is used to cast a ray from the Aim Origin gameobject to the center of the camera or an assigned Target.
It is commonly used to Aim Weapons, do a Head Look At, or for the Strafing logic.
Requirements
This component needs to have an Aim Origin reference.
General
Active
Enable/Disable the Aim Logic. Use this to avoid doing raycasting while the aim component is not used.
Update Mode
Where the Aim Logic will take place, on the Fixed or Late Update cycle.
Aim Side
It's used for planning whether your Camera Rig can be on the Left or Right side of your character when aiming.
It uses the On Aim event to send the value -1 if the camera is on the Left side, 1 if is on the Right side, or 0 if the Amining logic is not Active.
Aim Origin
The Transform object used to determine the origin position of the Aim Ray. Usually the head of the character.
Layer
Which layers the Aim Ray will interact with
Trigger interaction
Will the Aim Ray interact with triggers?
Raycast Radius
If this value is greater than zero, the Aim Ray will be using SphereCast instead of RayCast.
Ray Hits
Increase the precision of the Raycasting logic.
Since I'm using the NonAlloc Version to make faster raycasting, this doesn't always create accurate Hits when the ray touches more than one object. Increasing the hits increases the accuracy.
Smoothness
Lerp value for changing the Ray cast hit position. Lower values, smooth Aiming
References
Target
Replaces the Aim Logic from Aiming with the Camera to Aiming towards a target.
Use Camera
The Aim Target will use a camera to cast a ray from the camera's position
Camera
Reference for the Main Camera
Screen Center
When using a Camera as the Ray Origin. An offset will be added to the center of the screen where the Ray will be cast.
Ignore
Extra Transform Reference to Ignore for the Aim Logic. This is used for example with the Rider when is mounting the horse and the Weapon is Aiming. The Horse is set as the extra transform so Aim Ray does not hit the horse gameobject and its children.
Aim Position
It moves the Transform assigned to this parameter to the Hit Position. It is used to create an assistance to see where the Aim Ray Ends. It also hides this transform when the Aim is not Active.
Events
On Aiming (Boolean)
Invoked when the Aim Logic is Enabled/Disabled
On Hit (Transform)
Invoked when an object is hit by the Aim Ray.
On Aim Ray Target (transform)
Invoke the Transform the Aim Ray touches.
On Using Target ()
Invoked true or false when a new Target is assigned
On Clear Target ()
Invoked when the Target on the Aim component is removed
On Set Target ()
Invoked when a new Target object is assigned
On Screen Center (Vector3)
Invoke the current Screen position.
On Aim Side (Int)
Invoke -1 if the Main Camera or Target is on the Left or 1 if it's on the Right side of the character. Useful to change states on the Camera Rig System
Last updated