Post by tsuyoiraion on Dec 2, 2018 23:58:28 GMT
Static Cameras LockOn Fix
While diving into the lock on system I noticed that it highly relies on the camera to rotate the player towards the locked on target, no matter what state the camera is in. So for static cameras this is not ideal, for games like RE and other games that use static cams.
So I went in and made a small adjustment to make this work as I wanted and thought i'd share the results.
You'll need to make some small additions to a few scripts, lets go over those:
1. vLockOnShooter - Uses reference values & custom wait/buff before grabbing target transform
At the top add - using Invector.vCamera;
As well as the needed values:
public vThirdPersonController thirdPerCont;
public vThirdPersonCamera thirdPerCam;
public float waitTime;
Make sure to set the wait time so it waits a decent amount of time for the lock on target to be grabbed by the camera before referencing it.
You can add this anywhere else:
void FixedUpdate(){
if(isLockingOn){
thirdPerCont.RotateTowards(thirdPerCam.lockTarget);
}
}
public IEnumerator BuffLockOn(){
yield return new WaitForSeconds(waitTime);
thirdPerCont.RotateTowards(thirdPerCam.lockTarget);
}
Last inside LockOnInput, under LockOn(isLockingOn), add:
StartCoroutine("BuffLockOn");
2. vThirdPersonController - Rotates player
Right underneath RotateWithAnotherTransform, add:
public void RotateTowards(Transform rotTrans) {
transform.LookAt(rotTrans);
}
That should do it, now when you lock on to an enemy with static cameras, the player will always face the enemy, I suggest using Strafing when locked on to ensure smooth rotation.
You could of course omit the third person controller part and move that to lock on but i like having it in TP Controller
Enjoy!