Responsible for trigger interaction is TriggerManagement component on player object.
It holds OnTriggerStay and other methods used for detecting for collisions with trigger colliders on scene.
All scene triggers must derive from Trigger class. There are specialized premade trigger classes/components which reside in 'Prefabs/Triggers' folder ( like ClimbOn, JumpOver etc.. ) and generalized GenericTrigger component.
You can use from the collection of premade triggers or create your own with TriggerCreator tool which uses GenericTrigger.
TriggerCreator tool can be opened by clicking on
'Tools/GC Character Controller/TriggerCreator'
After TriggerCreator widow is opened
1) assign name of trigger ( trigger object name )
2) trigger object ( usualy cube or any other collider which will be used as a trigger )
3) player object ( player game object with animator component. New animator state with assigned clip will be created in that animator )
4) trigger animation clip ( animation clip which will start on trigger - like open door, jump on, climb etc... Animation clip will be added to player object animator new state )
5) trigger state name ( new state name that will be created - be carefull to not have duplicate names )
6) transition to state ( enter name of state with wich trigger clip will be connected to
it can be changed or added to later )
7) target ( transform which will be used as position and/or rotation target. Player have option to rotate or/and move to target postion )
8) angle condition ( angle at which player must be under in relation to trigger transform forward direction to start trigger )
9) switch target direction ( added so target can be used from opposite side. Player rotates towards direction of target forward direction, so if trigger is on opposite side use opposite of forward )
10) replace ( if new animator state already exists - it will replace clip otherwise it will discard changes )
11) disable physics on trigger start ( disable collider, rigidbody set to kinematic and gravity to false so that physics do not conflict with trigger animation )
12) assign action callbacks if needed
- OnTriggerStart
- OnMatchTargetStart
- OnTriggerEnd ( you can add methods to execute upon trigger start, match target start and trigger end - methods holds parameters (GenericTrigger, TriggerManagement) - look at the Test.cs script for examples.
13) input ( input at which trigger will start - it is a bitmak and can be combined )
14) lerp type ( player can use interpolation on trigger entering so player can move/rotate in direction of trigger forward vector or direction to target)
15) add match target ( add match target setup to trigger for finer refinement )
If Add Match Target Is Set To True
- match target start ( time at which match target will start - also OnMatchTargetStart will execute )
16) match target end ( time to reach match target effector to assigned target )
17) match target ( transform to use to act as an effecter - usualy same target as 'target' field)
NOTE: After clicking on create 'GenericTrigger' component will be place on trigger object. In GenericTrigger you can assign match target avatarTarget - by default its RightHand.
Triggers usually work by - upon player entering trigger collider and condition are met - and input is passed - lerp starts ( usualy rotation so player face target or can also lerp to position ( like in front of door or panel )) - then animation clip starts ( with match target if exists ) - after animation ends - player return to assigned state ( usualy Locomotion).
There are also examples where trigger does not start animation ( WeaponTrigger ).
Hands and feet placement:
- to have hand and feet placed by unity inverse kinematics - IKHelper script is used.
- you can use point, line or plane placement type.
- to use IK, these are the steps:
a) enable IK for certain limb( IKHelper.LeftHandIKEnabled for instance)
b) assign type of placement for hand or feet ( IKHelper.IKMode Point, line, Plane )
c) assign IK point (Vector3)LHPosition or
(Transform)LHTargetTransform ( Transform overrides Vector3 )
if you use point IKMode.
OR
assign 2 line points ( 2 Vector3) m_LeftHandPtA, m_LeftHandPtB or line transform which uses line along x axis ( Transform overrides Vector3 - s)
if you use line IKMode
OR
assign plane for IK usage (( Plane)LeftFootPlane for instance)
d) in animation clip that will use IK in import settings assign new curves:
pLeftHandIKWeight for left hand,
pRightHandIKWeight for right hand,
pLeftFootIKWeight for left foot,
pRightFootIKWeight for right foot.
If all is setup then ik enabled limb will position itself to assigned point/line/plane based on weight assigned in animatiion clip curve.
For Trigger and TriggerCreator tutorial watch:
Package contains amount of built in / premade triggers like cover, doors, ledge climbing, push/pull object etc...
For built in / premade triggers watch: