plantilla base para movimiento básico
This commit is contained in:
Robii Aragon
2026-02-05 05:07:55 -08:00
parent ed7b223c04
commit fd87a6ffd5
14441 changed files with 13711084 additions and 20 deletions

View File

@@ -0,0 +1,567 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class IKFootSystem : OnAnimatorIKComponent
{
[Header ("Main Settings")]
[Space]
public bool IKFootSystemEnabled = true;
public LayerMask layerMask;
[Space]
public float IKWeightEnabledSpeed = 10;
public float IKWeightDisabledSpeed = 2;
public float extraFootOffset = 0.005f;
public float minSurfaceAngleToUseIKFoot = 0.1f;
public float maxSurfaceAngleToUseIKFoot = 0;
[Space]
[Header ("Hips Settings")]
[Space]
//public bool adjustHipsPositionEnabled = true;
public float hipsMovementSpeed = 1.2f;
public float hipsPositionUpClampAmount = 0.2f;
public float hipsPositionDownClampAmount = -0.2f;
public float hipsPositionUpMovingClampAmount = 0.2f;
public float hipsPositionDownMovingClampAmount = -0.2f;
[Space]
[Header ("Other Settings")]
[Space]
public bool disableComponentIfIKSystemNotEnabledOnStart = true;
[Space]
[Header ("Leg Info List Settings")]
[Space]
public List<legInfo> legInfoList = new List<legInfo> ();
[Space]
[Header ("Debug")]
[Space]
public bool canUseIkFoot;
public bool IKFootPaused;
public bool removeIKValue;
public float currentSurfaceAngle;
public bool fullBodyAwarenessActive;
public bool canAdjustHipsPosition = true;
public Vector3 hipsPosition;
[Space]
[Header ("Components")]
[Space]
public playerController playerControllerManager;
public Animator mainAnimator;
public Transform playerTransform;
public Transform hips;
float newHipsOffset;
bool usingIKFootPreviously;
float currentHipsOffset;
bool playerOnGround;
bool currentLegIsRight;
RaycastHit hit;
legInfo currentLegInfo;
float currentRaycastDistance;
float currentAdjustmentSpeed;
Vector3 currentRaycastPosition;
float newRaycastDistance;
float newOffset;
Vector3 newFootPosition;
Quaternion newFootRotation;
float targetWeight;
Vector3 localFootPosition;
Vector3 newKneePosition;
bool initialPositionAssigned;
Vector3 newRaycastPosition;
Vector3 newLocalHipsPosition;
bool playerIsMoving;
bool checkRaycast;
int i;
Vector3 currentTransfrormUp;
Vector3 currentGravityNormal;
float currentWeightToApply;
AvatarIKGoal currentIKGoal;
AvatarIKHint currenIKHint;
float minIKValue = 0.001f;
Vector3 rightFootHitPoint;
Vector3 leftFootHitPoint;
bool fullBodyAwarenessActiveChecked;
void Start ()
{
calculateInitialFootValues ();
}
public void calculateInitialFootValues ()
{
for (i = 0; i < 2; i++) {
currentLegInfo = legInfoList [i];
if (currentLegInfo.useCustomOffset) {
currentLegInfo.offset = currentLegInfo.customOffset;
} else {
currentLegInfo.offset = playerTransform.InverseTransformPoint (currentLegInfo.foot.position).y;
}
if (currentLegInfo.useCustomMaxLegLength) {
currentLegInfo.maxLegLength = currentLegInfo.customMaxLegLength;
} else {
currentLegInfo.maxLegLength = playerTransform.InverseTransformPoint (currentLegInfo.lowerLeg.position).y;
}
}
hipsPosition = hips.position;
if (disableComponentIfIKSystemNotEnabledOnStart) {
if (!IKFootSystemEnabled) {
enabled = false;
}
}
}
void LateUpdate ()
{
if (!IKFootSystemEnabled) {
return;
}
canUseIkFoot = true;
if (playerControllerManager.isPlayerDead () ||
playerControllerManager.isPlayerDriving () ||
playerControllerManager.isPlayerOnFirstPerson () ||
(playerControllerManager.isPlayerOnFFOrZeroGravityModeOn () && !playerControllerManager.isPlayerOnGround ()) ||
playerControllerManager.isUsingJetpack () ||
playerControllerManager.isFlyingActive () ||
playerControllerManager.isSwimModeActive () ||
playerControllerManager.isMovingOnPlatformActive ()) {
canUseIkFoot = false;
}
if (usingIKFootPreviously != canUseIkFoot) {
if (!usingIKFootPreviously) {
hipsPosition = playerTransform.InverseTransformPoint (hips.position);
}
usingIKFootPreviously = canUseIkFoot;
}
if (!canUseIkFoot) {
return;
}
fullBodyAwarenessActive = playerControllerManager.isFullBodyAwarenessActive ();
if (fullBodyAwarenessActive) {
if (!fullBodyAwarenessActiveChecked) {
canAdjustHipsPosition = false;
fullBodyAwarenessActiveChecked = true;
}
} else {
if (fullBodyAwarenessActiveChecked) {
canAdjustHipsPosition = true;
fullBodyAwarenessActiveChecked = false;
}
}
//&& adjustHipsPositionEnabled
if (canAdjustHipsPosition) {
hips.position = playerTransform.TransformPoint (hipsPosition);
}
if (!initialPositionAssigned) {
initialPositionAssigned = true;
}
}
public override void updateOnAnimatorIKState ()
{
if (!IKFootSystemEnabled) {
return;
}
if (!canUseIkFoot) {
return;
}
playerOnGround = playerControllerManager.isPlayerOnGround ();
newHipsOffset = 0f;
currentTransfrormUp = playerTransform.up;
if (playerOnGround) {
for (i = 0; i < 2; i++) {
currentLegInfo = legInfoList [i];
//raycast from the foot
currentRaycastPosition = getNewRaycastPosition (currentLegInfo.foot.position, currentLegInfo.lowerLeg.position, out currentRaycastDistance);
newRaycastDistance = currentRaycastDistance + currentLegInfo.offset + currentLegInfo.maxLegLength - (extraFootOffset * 2);
checkRaycast = true;
if (float.IsNaN (currentRaycastPosition.x) && float.IsNaN (currentRaycastPosition.y) && float.IsNaN (currentRaycastPosition.z)) {
checkRaycast = false;
}
if (checkRaycast) {
if (Physics.Raycast (currentRaycastPosition, -currentTransfrormUp, out hit, newRaycastDistance, layerMask)) {
currentLegInfo.raycastDistance = currentRaycastDistance;
currentLegInfo.surfaceDistance = hit.distance;
currentLegInfo.surfacePoint = hit.point;
currentLegInfo.surfaceNormal = hit.normal;
} else {
currentLegInfo.surfaceDistance = float.MaxValue;
}
} else {
currentLegInfo.surfaceDistance = float.MaxValue;
}
//raycast from the toe, if a closer object is found, the raycast used is the one in the toe
currentRaycastPosition = getNewRaycastPosition (currentLegInfo.toes.position, currentLegInfo.lowerLeg.position, out currentRaycastDistance);
newRaycastDistance = currentRaycastDistance + currentLegInfo.offset + currentLegInfo.maxLegLength - (extraFootOffset * 2);
checkRaycast = true;
if (float.IsNaN (currentRaycastPosition.x) && float.IsNaN (currentRaycastPosition.y) && float.IsNaN (currentRaycastPosition.z)) {
checkRaycast = false;
}
if (checkRaycast) {
if (Physics.Raycast (currentRaycastPosition, -currentTransfrormUp, out hit, newRaycastDistance, layerMask)) {
if (hit.distance < currentLegInfo.surfaceDistance && hit.normal == currentTransfrormUp) {
currentLegInfo.raycastDistance = currentRaycastDistance;
currentLegInfo.surfaceDistance = hit.distance;
currentLegInfo.surfacePoint = hit.point;
currentLegInfo.surfaceNormal = hit.normal;
}
}
}
//Debug.DrawLine (currentRaycastPosition, currentRaycastPosition + playerTransform.up * 4, Color.red, 3);
if (currentLegInfo.surfaceDistance != float.MaxValue) {
newOffset = currentLegInfo.surfaceDistance - currentLegInfo.raycastDistance - playerTransform.InverseTransformPoint (currentLegInfo.foot.position).y;
if (newOffset > newHipsOffset) {
newHipsOffset = newOffset;
}
}
if (currentIKGoal == AvatarIKGoal.RightFoot) {
rightFootHitPoint = currentLegInfo.surfacePoint;
} else {
leftFootHitPoint = currentLegInfo.surfacePoint;
}
}
}
playerIsMoving = playerControllerManager.isPlayerMoving (0);
if (playerIsMoving) {
newHipsOffset = Mathf.Clamp (newHipsOffset, hipsPositionDownMovingClampAmount, hipsPositionUpMovingClampAmount);
} else {
newHipsOffset = Mathf.Clamp (newHipsOffset, hipsPositionDownClampAmount, hipsPositionUpClampAmount);
}
if (IKFootPaused) {
newHipsOffset = 0;
}
//set hips position
if (initialPositionAssigned) {
currentHipsOffset = Mathf.Lerp (currentHipsOffset, newHipsOffset, hipsMovementSpeed * Time.fixedDeltaTime);
} else {
currentHipsOffset = newHipsOffset;
}
hipsPosition = playerTransform.InverseTransformPoint (hips.position);
hipsPosition.y -= currentHipsOffset;
currentGravityNormal = playerControllerManager.getCurrentNormal ();
//set position and rotation on player's feet
for (i = 0; i < 2; i++) {
currentLegInfo = legInfoList [i];
currentIKGoal = currentLegInfo.IKGoal;
newFootPosition = mainAnimator.GetIKPosition (currentIKGoal);
newFootRotation = mainAnimator.GetIKRotation (currentIKGoal);
targetWeight = currentLegInfo.IKWeight - 1;
currentAdjustmentSpeed = IKWeightDisabledSpeed;
if (playerOnGround) {
if (currentLegInfo.surfaceDistance != float.MaxValue) {
if (playerTransform.InverseTransformDirection (newFootPosition - currentLegInfo.surfacePoint).y - currentLegInfo.offset - extraFootOffset - currentHipsOffset < 0) {
localFootPosition = playerTransform.InverseTransformPoint (newFootPosition);
localFootPosition.y = playerTransform.InverseTransformPoint (currentLegInfo.surfacePoint).y;
newFootPosition = playerTransform.TransformPoint (localFootPosition) +
(currentLegInfo.offset + currentHipsOffset - extraFootOffset) * currentTransfrormUp;
newFootRotation = Quaternion.LookRotation (Vector3.Cross (currentLegInfo.surfaceNormal, newFootRotation * -Vector3.right), currentTransfrormUp);
targetWeight = currentLegInfo.IKWeight + 1;
currentAdjustmentSpeed = IKWeightEnabledSpeed;
}
}
}
removeIKValue = false;
if (IKFootPaused) {
removeIKValue = true;
}
if (!removeIKValue) {
currentSurfaceAngle = playerControllerManager.getCurrentSurfaceHitAngle ();
if (currentSurfaceAngle < minSurfaceAngleToUseIKFoot) {
removeIKValue = true;
}
if (maxSurfaceAngleToUseIKFoot > 0) {
if (Mathf.Abs (currentSurfaceAngle) > maxSurfaceAngleToUseIKFoot) {
removeIKValue = true;
}
}
}
if (!removeIKValue) {
if (!playerIsMoving && currentLegInfo.surfaceNormal == currentGravityNormal) {
float footHeightDifference = Mathf.Abs (playerTransform.InverseTransformPoint (leftFootHitPoint).y) -
Mathf.Abs (playerTransform.InverseTransformPoint (rightFootHitPoint).y);
if (Mathf.Abs (footHeightDifference) < 0.02f) {
removeIKValue = true;
}
}
}
if (removeIKValue) {
targetWeight = 0;
}
if (initialPositionAssigned) {
currentLegInfo.IKWeight = Mathf.Clamp01 (Mathf.Lerp (currentLegInfo.IKWeight, targetWeight, currentAdjustmentSpeed * Time.fixedDeltaTime));
} else {
currentLegInfo.IKWeight = Mathf.Clamp01 (targetWeight);
}
currentWeightToApply = currentLegInfo.IKWeight;
if (currentWeightToApply >= minIKValue) {
mainAnimator.SetIKPosition (currentIKGoal, newFootPosition);
mainAnimator.SetIKRotation (currentIKGoal, newFootRotation);
mainAnimator.SetIKPositionWeight (currentIKGoal, currentWeightToApply);
mainAnimator.SetIKRotationWeight (currentIKGoal, currentWeightToApply);
}
if (currentLegInfo.useKneeIK) {
if (!playerIsMoving || !currentLegInfo.adjustOnlyWhenNotMoving) {
currenIKHint = currentLegInfo.IKHint;
newKneePosition = mainAnimator.GetIKHintPosition (currenIKHint);
newKneePosition += (currentLegInfo.kneeOffset.x * playerTransform.right) +
(currentLegInfo.kneeOffset.y * playerTransform.up) +
(currentLegInfo.kneeOffset.z * playerTransform.forward);
if (currentLegInfo.useLerpForIKHintWeight) {
currentLegInfo.currentIKHintWeight = Mathf.Clamp01 (Mathf.Lerp (currentLegInfo.currentIKHintWeight,
currentWeightToApply, currentLegInfo.lerpSpeedForIKHintWeight * Time.fixedDeltaTime));
} else {
currentLegInfo.currentIKHintWeight = currentWeightToApply;
}
currentLegInfo.currentIKHintWeight *= currentLegInfo.IKHintWeightMultiplier;
if (removeIKValue) {
currentLegInfo.currentIKHintWeight = 0;
}
mainAnimator.SetIKHintPositionWeight (currenIKHint, currentLegInfo.currentIKHintWeight);
mainAnimator.SetIKHintPosition (currenIKHint, newKneePosition);
}
}
}
}
public Vector3 getNewRaycastPosition (Vector3 targetTransformPosition, Vector3 lowerLegPosition, out float newDistance)
{
newRaycastPosition = playerTransform.InverseTransformPoint (targetTransformPosition);
newLocalHipsPosition = playerTransform.InverseTransformPoint (lowerLegPosition);
newDistance = (newLocalHipsPosition.y - newRaycastPosition.y);
newRaycastPosition.y = newLocalHipsPosition.y;
return playerTransform.TransformPoint (newRaycastPosition);
}
public void setIKFootPausedState (bool state)
{
IKFootPaused = state;
}
public void setLegsInfo (Transform newHips, Transform rightLowerLeg, Transform leftLowerLeg, Transform rightFoot, Transform leftFoot, Transform rightToes, Transform leftToes)
{
hips = newHips;
for (i = 0; i < legInfoList.Count; i++) {
if (legInfoList [i].IKGoal == AvatarIKGoal.RightFoot) {
legInfoList [i].lowerLeg = rightLowerLeg;
legInfoList [i].foot = rightFoot;
legInfoList [i].toes = rightToes;
} else {
legInfoList [i].lowerLeg = leftLowerLeg;
legInfoList [i].foot = leftFoot;
legInfoList [i].toes = leftToes;
}
}
updateComponent ();
}
public void setIKFootSystemEnabledState (bool state)
{
IKFootSystemEnabled = state;
if (IKFootSystemEnabled && disableComponentIfIKSystemNotEnabledOnStart) {
if (Application.isPlaying) {
if (!enabled) {
enabled = true;
}
}
}
}
public void setIKFootSystemEnabledStateFromEditor (bool state)
{
setIKFootSystemEnabledState (state);
updateComponent ();
}
public void updateComponent ()
{
GKC_Utils.updateComponent (this);
}
[System.Serializable]
public class legInfo
{
[Header ("Main Settings")]
[Space]
public string Name;
public AvatarIKGoal IKGoal;
[Space]
public Transform lowerLeg;
public Transform foot;
public Transform toes;
[Space]
[Header ("Other Settings")]
[Space]
public bool useCustomOffset;
public float customOffset;
[Space]
public bool useCustomMaxLegLength;
public float customMaxLegLength;
[Space]
[Header ("Knee Settings")]
[Space]
public bool useKneeIK;
public AvatarIKHint IKHint;
public Vector3 kneeOffset;
public bool adjustOnlyWhenNotMoving;
public float IKHintWeightMultiplier = 1;
public bool useLerpForIKHintWeight;
public float lerpSpeedForIKHintWeight;
[Space]
[Header ("Debug")]
[Space]
public float IKWeight;
public float offset;
public float maxLegLength;
public float raycastDistance;
public float surfaceDistance;
public Vector3 surfacePoint;
public Vector3 surfaceNormal;
[Space]
[Space]
public float currentIKHintWeight;
}
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: 92dee05715eb2d342a993d775438908c
timeCreated: 1548926669
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 40995
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
packageVersion: 3.77g
assetPath: Assets/Game Kit Controller/Scripts/Player/Animator IK/IKFootSystem.cs
uploadId: 814740

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: e7b3304a7d85fff42a88d74355f0f2f2
timeCreated: 1457548976
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 40995
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
packageVersion: 3.77g
assetPath: Assets/Game Kit Controller/Scripts/Player/Animator IK/IKSystem.cs
uploadId: 814740

View File

@@ -0,0 +1,55 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class OnAnimatorIKComponent : MonoBehaviour
{
public bool updateIKEnabled = true;
public virtual void updateOnAnimatorIKState ()
{
if (!updateIKEnabled) {
return;
}
}
public void setUpdateIKEnabledState (bool state)
{
updateIKEnabled = state;
}
public bool isUpdateIKEnabled ()
{
return updateIKEnabled;
}
public virtual void setActiveState (bool state)
{
}
public virtual void enableBothHands ()
{
enableOrDisableRightOrLeftHand (true, false, true);
}
public virtual void enableOnlyLeftHand ()
{
enableOrDisableRightOrLeftHand (true, false, false);
}
public virtual void enableOnlyRightHand ()
{
enableOrDisableRightOrLeftHand (true, true, false);
}
public virtual void enableOrDisableRightOrLeftHand (bool state, bool isRightHand, bool setStateOnBothHands)
{
}
public virtual void setCharacterElements (GameObject newCharacter)
{
}
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: d5d9fd7fda0983a4a8ae9ff8f4009681
timeCreated: 1626186969
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 40995
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
packageVersion: 3.77g
assetPath: Assets/Game Kit Controller/Scripts/Player/Animator IK/OnAnimatorIKComponent.cs
uploadId: 814740

View File

@@ -0,0 +1,445 @@
using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.Events;
public class handsOnMeleeWeaponIKSystem : OnAnimatorIKComponent
{
[Header ("Main Settings")]
[Space]
public bool adjustHandsEnabled = true;
public float weightLerpSpeed = 6;
public float busyBodyPartWeightLerpSpeed = 3;
public float minWaitTimeToActiveHands = 0.3f;
[Space]
[Header ("Hands Info List Settings")]
[Space]
public List<handInfo> handInfoList = new List<handInfo> ();
[Space]
[Header ("Debug")]
[Space]
public bool showDebugPrint;
public bool handsOnMeleeActive;
public bool usingHands;
public bool isBusy;
public bool adjustHandsPaused;
public bool smoothBusyDisableActive;
public bool handsCheckPausedWithDelayActive;
[Space]
[Header ("Event Settings")]
[Space]
public bool useEventsOnActiveStateChange;
public UnityEvent eventOnActive;
public UnityEvent eventOnDeactivate;
[Space]
[Header ("Component Elements")]
[Space]
public Animator animator;
public IKSystem IKManager;
public playerController playerControllerManager;
public meleeWeaponsGrabbedManager mainMeleeWeaponsGrabbedManager;
handInfo currentHandInfo;
bool isThirdPersonView;
float originalWeightLerpSpeed;
float currentWeightToApply;
AvatarIKGoal currentIKGoal;
int handInfoListCount;
float minIKValue = 0.001f;
Coroutine delayToResumeStateCoroutine;
bool valuesInitialized;
float lastTimeHandsActive = 0;
float currentWeightLerpSpeed;
public override void updateOnAnimatorIKState ()
{
if (handsOnMeleeActive) {
isThirdPersonView = !playerControllerManager.isPlayerOnFirstPerson ();
usingHands = IKManager.getUsingHands ();
if (IKManager.isObjectGrabbed ()) {
usingHands = false;
}
isBusy = playerIsBusy ();
if (Time.time < lastTimeHandsActive + minWaitTimeToActiveHands) {
isBusy = true;
}
bool IKBodyPaused = IKManager.isIKBodyPaused ();
bool pauseIKBodyResult = playerControllerManager.isActionActive () ||
mainMeleeWeaponsGrabbedManager.isAimingBowActive () ||
mainMeleeWeaponsGrabbedManager.isCuttingModeActive ();
if (!isBusy || smoothBusyDisableActive) {
for (int j = 0; j < handInfoListCount; j++) {
currentHandInfo = handInfoList [j];
if (currentHandInfo.IKBodyPartEnabled) {
if (IKBodyPaused || pauseIKBodyResult) {
if (!currentHandInfo.bodyPartBusy) {
currentHandInfo.bodyPartBusy = true;
currentHandInfo.IKBodyWeigthTarget = 0;
}
} else {
if (!usingHands) {
if (currentHandInfo.bodyPartBusy) {
currentHandInfo.bodyPartBusy = false;
currentHandInfo.IKBodyWeigthTarget = 1;
} else {
currentHandInfo.IKBodyWeigthTarget = 1;
}
} else {
if (!currentHandInfo.bodyPartBusy) {
currentHandInfo.bodyPartBusy = true;
currentHandInfo.IKBodyWeigthTarget = 0;
}
}
}
if (currentHandInfo.currentIKWeight != currentHandInfo.IKBodyWeigthTarget) {
if (currentHandInfo.bodyPartBusy) {
currentWeightLerpSpeed = busyBodyPartWeightLerpSpeed;
} else {
currentWeightLerpSpeed = weightLerpSpeed;
}
currentHandInfo.currentIKWeight = Mathf.MoveTowards (currentHandInfo.currentIKWeight,
currentHandInfo.IKBodyWeigthTarget, Time.fixedDeltaTime * currentWeightLerpSpeed);
}
bool applyIKToBodyPart = false;
if (!currentHandInfo.bodyPartBusy) {
currentHandInfo.IKGoalPosition = currentHandInfo.targetToFollow.position;
currentHandInfo.IKGoalRotation = currentHandInfo.targetToFollow.rotation;
applyIKToBodyPart = true;
} else if (currentHandInfo.currentIKWeight != currentHandInfo.IKBodyWeigthTarget) {
applyIKToBodyPart = true;
}
if (applyIKToBodyPart) {
currentWeightToApply = currentHandInfo.currentIKWeight;
if (currentWeightToApply > minIKValue) {
currentIKGoal = currentHandInfo.IKGoal;
animator.SetIKRotationWeight (currentIKGoal, currentWeightToApply);
animator.SetIKPositionWeight (currentIKGoal, currentWeightToApply);
animator.SetIKPosition (currentIKGoal, currentHandInfo.IKGoalPosition);
animator.SetIKRotation (currentIKGoal, currentHandInfo.IKGoalRotation);
}
}
}
}
} else {
for (int j = 0; j < handInfoListCount; j++) {
currentHandInfo = handInfoList [j];
currentHandInfo.bodyPartBusy = false;
currentHandInfo.IKBodyWeigthTarget = 0;
currentHandInfo.currentIKWeight = 0;
}
}
}
}
public bool playerIsBusy ()
{
return
(usingHands && !IKManager.isObjectGrabbed ()) ||
!isThirdPersonView ||
playerControllerManager.isPlayerOnFFOrZeroGravityModeOn () ||
playerControllerManager.isUsingCloseCombatActive () ||
playerControllerManager.isPlayerDead () ||
adjustHandsPaused ||
playerControllerManager.isUsingJetpack () ||
playerControllerManager.isFlyingActive () ||
playerControllerManager.isSwimModeActive ();
}
public void setWeightLerpSpeedValue (float newValue)
{
weightLerpSpeed = newValue;
}
public void setOriginalWeightLerpSpeed ()
{
setWeightLerpSpeedValue (originalWeightLerpSpeed);
}
public void setAdjustHandsPausedState (bool state)
{
adjustHandsPaused = state;
}
public void setSmoothBusyDisableActiveState (bool state)
{
smoothBusyDisableActive = state;
}
public void setAdjustHandsEnabledState (bool state)
{
adjustHandsEnabled = state;
}
public void enableHandsCheckPausedWithDelayActive (float duration)
{
stopUpdateDelayToResumeStateCoroutine ();
delayToResumeStateCoroutine = StartCoroutine (updateDelayToResumeStateCoroutine (duration));
}
public void stopUpdateDelayToResumeStateCoroutine ()
{
if (delayToResumeStateCoroutine != null) {
StopCoroutine (delayToResumeStateCoroutine);
}
handsCheckPausedWithDelayActive = false;
}
IEnumerator updateDelayToResumeStateCoroutine (float duration)
{
handsCheckPausedWithDelayActive = true;
WaitForSeconds delay = new WaitForSeconds (duration);
yield return delay;
handsCheckPausedWithDelayActive = false;
}
public override void enableBothHands ()
{
enableOrDisableRightOrLeftHand (true, false, true);
}
public override void enableOnlyLeftHand ()
{
enableOrDisableRightOrLeftHand (true, false, false);
}
public override void enableOnlyRightHand ()
{
enableOrDisableRightOrLeftHand (true, true, false);
}
public override void enableOrDisableRightOrLeftHand (bool state, bool isRightHand, bool setStateOnBothHands)
{
if (showDebugPrint) {
print (state + " " + isRightHand + " " + setStateOnBothHands);
}
handInfoListCount = handInfoList.Count;
for (int j = 0; j < handInfoListCount; j++) {
currentHandInfo = handInfoList [j];
if (setStateOnBothHands) {
currentHandInfo.IKBodyPartEnabled = state;
} else {
if (currentHandInfo.isRightHand) {
if (isRightHand) {
currentHandInfo.IKBodyPartEnabled = state;
} else {
currentHandInfo.IKBodyPartEnabled = false;
currentHandInfo.bodyPartBusy = false;
currentHandInfo.IKBodyWeigthTarget = 0;
currentHandInfo.currentIKWeight = 0;
}
} else {
if (isRightHand) {
currentHandInfo.IKBodyPartEnabled = false;
currentHandInfo.bodyPartBusy = false;
currentHandInfo.IKBodyWeigthTarget = 0;
currentHandInfo.currentIKWeight = 0;
} else {
currentHandInfo.IKBodyPartEnabled = state;
}
}
}
bool checkEnableEventsResult = currentHandInfo.IKBodyPartEnabled;
if (currentHandInfo.useEventOnIKPartEnabledStateChange) {
if (checkEnableEventsResult) {
currentHandInfo.eventOnIKPartEnabled.Invoke ();
} else {
currentHandInfo.eventOnIKPartDisabled.Invoke ();
}
}
if (showDebugPrint) {
print (currentHandInfo.Name + " " + checkEnableEventsResult + " " + currentHandInfo.bodyPartBusy);
}
}
if (showDebugPrint) {
for (int j = 0; j < handInfoListCount; j++) {
currentHandInfo = handInfoList [j];
print (currentHandInfo.isRightHand + " " + currentHandInfo.IKBodyPartEnabled);
}
}
}
public override void setActiveState (bool state)
{
if (!adjustHandsEnabled) {
return;
}
if (handsOnMeleeActive == state) {
return;
}
handsOnMeleeActive = state;
if (handsOnMeleeActive) {
if (!valuesInitialized) {
originalWeightLerpSpeed = weightLerpSpeed;
handInfoListCount = handInfoList.Count;
valuesInitialized = true;
}
lastTimeHandsActive = Time.time;
} else {
for (int j = 0; j < handInfoListCount; j++) {
currentHandInfo = handInfoList [j];
currentHandInfo.bodyPartBusy = false;
currentHandInfo.IKBodyWeigthTarget = 0;
currentHandInfo.currentIKWeight = 0;
}
}
if (useEventsOnActiveStateChange) {
if (state) {
eventOnActive.Invoke ();
} else {
eventOnDeactivate.Invoke ();
}
}
}
public void disableStateIfNotCurrentlyActiveOnIKSystem ()
{
if (handsOnMeleeActive) {
if (!IKManager.checkIfTemporalOnAnimatorIKComponentIfIsCurrent (this)) {
setActiveState (false);
}
}
}
//EDITOR FUNCTIONS
public void setAdjustHandsEnabledStateFromEditor (bool state)
{
setAdjustHandsEnabledState (state);
updateComponent ();
}
void updateComponent ()
{
GKC_Utils.updateComponent (this);
}
[System.Serializable]
public class handInfo
{
[Header ("Main Settings")]
[Space]
public string Name;
public bool IKBodyPartEnabled = true;
public bool isRightHand;
public Transform targetToFollow;
[Space]
[Header ("IK Settings")]
[Space]
public AvatarIKGoal IKGoal;
[Space]
[Header ("Debug")]
[Space]
public bool bodyPartBusy;
public float currentIKWeight;
public float IKBodyWeigthTarget;
[HideInInspector] public Vector3 IKGoalPosition;
[HideInInspector] public Quaternion IKGoalRotation;
[Space]
[Header ("Event Settings")]
[Space]
public bool useEventOnIKPartEnabledStateChange;
public UnityEvent eventOnIKPartEnabled;
public UnityEvent eventOnIKPartDisabled;
}
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: 2f06345fd3ad781458c9f7b286542fc0
timeCreated: 1698018505
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 40995
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
packageVersion: 3.77g
assetPath: Assets/Game Kit Controller/Scripts/Player/Animator IK/handsOnMeleeWeaponIKSystem.cs
uploadId: 814740

View File

@@ -0,0 +1,595 @@
using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;
public class handsOnSurfaceIKSystem : OnAnimatorIKComponent
{
[Header ("Main Settings")]
[Space]
public bool adjustHandsToSurfacesEnabled = true;
public LayerMask layerToAdjustHandsToSurfaces;
public float movementSpeedLerpSpeed = 2;
public float waitTimeAfterGroundToCheckSurface = 1.5f;
public float waitTimeAfterCrouchToCheckSurface = 1.5f;
public float weightLerpSpeed = 6;
public float maxHandsDistance = 3;
public float minMovingInputToUseWalkSpeed = 0.5f;
public float minIKWeightToUseWalkSpeed = 0.4f;
public bool pauseHandsOnSurfaceIfCloseCombatActive;
[Space]
[Header ("Hands Info List Settings")]
[Space]
public List<handsToSurfaceInfo> handsToSurfaceInfoList = new List<handsToSurfaceInfo> ();
[Space]
[Header ("Debug")]
[Space]
public bool usingHands;
public bool adjustHandsPaused;
public bool smoothBusyDisableActive;
public bool handsCheckPausedWithDelayActive;
public bool isBusy;
[Space]
[Header ("Gizmo Settings")]
[Space]
public bool showGizmo;
public Color gizmoColor = Color.white;
public float gizmoRadius;
[Space]
[Header ("Component Elements")]
[Space]
public Animator animator;
public IKSystem IKManager;
public playerController playerControllerManager;
public Transform playerTransform;
handsToSurfaceInfo currentHandInfo;
Vector3 rayDirection;
RaycastHit hit;
float movementSpeed;
float currentMovementSpeed;
bool isThirdPersonView;
bool onGround;
bool movingOnPlatformActive;
bool dead;
bool groundChecked;
float lastTimeOnGround;
bool crouchingChecked;
float lastTimeCrouch;
Vector3 currentPositionCenter;
float currentRotationSpeed;
float originalWeightLerpSpeed;
bool crouching;
Transform rightHandTransform;
Transform leftHandTransform;
bool isRightHand;
multipleRayInfo currentMultipleRayInfo;
Vector3 currentTransformUp;
Vector3 currentTransformForward;
Vector3 vector3Zero = Vector3.zero;
Quaternion targetRotation;
Vector3 currentHandPosition;
float currentWeightToApply;
AvatarIKGoal currentIKGoal;
int handsToSurfaceInfoListCount;
float minIKValue = 0.001f;
float currentDeltaTime;
Coroutine delayToResumeStateCoroutine;
void Start ()
{
originalWeightLerpSpeed = weightLerpSpeed;
rightHandTransform = animator.GetBoneTransform (HumanBodyBones.RightHand);
leftHandTransform = animator.GetBoneTransform (HumanBodyBones.LeftHand);
handsToSurfaceInfoListCount = handsToSurfaceInfoList.Count;
}
void FixedUpdate ()
{
if (!adjustHandsToSurfacesEnabled) {
return;
}
isThirdPersonView = !playerControllerManager.isPlayerOnFirstPerson ();
usingHands = IKManager.getUsingHands ();
onGround = playerControllerManager.isPlayerOnGround ();
movingOnPlatformActive = playerControllerManager.isMovingOnPlatformActive ();
isBusy = playerIsBusy ();
crouching = playerControllerManager.isCrouching ();
dead = playerControllerManager.isPlayerDead ();
if (groundChecked != onGround) {
groundChecked = onGround;
if (onGround) {
lastTimeOnGround = Time.time;
}
}
if (crouchingChecked != crouching) {
crouchingChecked = crouching;
if (!crouching) {
lastTimeCrouch = Time.time;
}
}
if (adjustHandsToSurfacesEnabled) {
if (!isBusy || smoothBusyDisableActive) {
currentTransformUp = playerTransform.up;
currentTransformForward = playerTransform.forward;
for (int j = 0; j < handsToSurfaceInfoListCount; j++) {
currentHandInfo = handsToSurfaceInfoList [j];
currentHandInfo.surfaceFound = false;
currentHandInfo.multipleRaycastHitNormal = vector3Zero;
currentHandInfo.multipleRaycastHitPoint = vector3Zero;
currentHandInfo.numberOfSurfacesFound = 0;
currentHandInfo.multipleRaycastDirection = vector3Zero;
for (int k = 0; k < currentHandInfo.raycastTransformList.Count; k++) {
currentMultipleRayInfo = currentHandInfo.raycastTransformList [k];
rayDirection = currentMultipleRayInfo.raycastTransform.forward;
if (currentMultipleRayInfo.raycastEnabled &&
Physics.Raycast (currentMultipleRayInfo.raycastTransform.position, rayDirection, out hit,
currentMultipleRayInfo.rayCastDistance, layerToAdjustHandsToSurfaces)) {
currentMultipleRayInfo.hitPoint = hit.point;
currentMultipleRayInfo.hitNormal = hit.normal;
currentHandInfo.surfaceFound = true;
currentHandInfo.multipleRaycastHitNormal += hit.normal;
currentHandInfo.multipleRaycastHitPoint += hit.point;
currentHandInfo.numberOfSurfacesFound++;
currentHandInfo.multipleRaycastDirection += rayDirection;
if (showGizmo) {
Debug.DrawRay (currentMultipleRayInfo.raycastTransform.position, hit.distance * rayDirection, Color.green);
}
} else {
if (showGizmo) {
Debug.DrawRay (currentMultipleRayInfo.raycastTransform.position,
currentMultipleRayInfo.rayCastDistance * rayDirection, Color.red);
}
}
}
if (smoothBusyDisableActive) {
currentHandInfo.surfaceFound = false;
if (currentWeightInBothHandsEqualTo (0)) {
smoothBusyDisableActive = false;
}
}
if (currentHandInfo.surfaceFound) {
currentHandInfo.handPosition =
(currentHandInfo.multipleRaycastHitPoint / currentHandInfo.numberOfSurfacesFound) +
(currentHandInfo.handSurfaceOffset * currentHandInfo.multipleRaycastDirection / currentHandInfo.numberOfSurfacesFound);
targetRotation = Quaternion.LookRotation (currentHandInfo.multipleRaycastDirection / currentHandInfo.numberOfSurfacesFound);
currentHandInfo.handRotation =
Quaternion.FromToRotation (currentTransformUp, currentHandInfo.multipleRaycastHitNormal / currentHandInfo.numberOfSurfacesFound) * targetRotation;
currentHandInfo.elbowPosition =
((currentHandInfo.multipleRaycastHitPoint / currentHandInfo.numberOfSurfacesFound) + currentHandInfo.raycastTransform.position) / 2 - currentTransformUp * 0.1f;
currentHandInfo.handWeight = 1;
if (currentHandInfo.useMinDistance) {
currentHandInfo.currentDistance = GKC_Utils.distance (currentHandInfo.raycastTransform.position, currentHandInfo.handPosition);
if (currentHandInfo.currentDistance < currentHandInfo.minDistance) {
currentHandInfo.surfaceFound = false;
}
}
}
if (handsCheckPausedWithDelayActive ||
!currentHandInfo.surfaceFound ||
movingOnPlatformActive ||
!onGround ||
Time.time < waitTimeAfterGroundToCheckSurface + lastTimeOnGround ||
crouching ||
Time.time < waitTimeAfterCrouchToCheckSurface + lastTimeCrouch ||
dead) {
currentHandInfo.handPosition = currentHandInfo.noSurfaceHandPosition.position;
currentHandInfo.handRotation = Quaternion.LookRotation (currentTransformForward);
currentHandInfo.elbowPosition = currentHandInfo.noSurfaceElbowPosition.position;
currentHandInfo.handWeight = 0;
}
if (playerControllerManager.isPlayerMoving (minMovingInputToUseWalkSpeed) &&
currentHandInfo.surfaceFound && currentHandInfo.currentHandWeight > minIKWeightToUseWalkSpeed) {
movementSpeed = currentHandInfo.walkingMovementSpeed;
} else {
movementSpeed = currentHandInfo.movementSpeed;
}
currentDeltaTime = Time.deltaTime;
currentMovementSpeed = Mathf.Lerp (currentMovementSpeed, movementSpeed, currentDeltaTime * movementSpeedLerpSpeed);
currentHandInfo.currentHandPosition = Vector3.Lerp (currentHandInfo.currentHandPosition, currentHandInfo.handPosition, currentDeltaTime * currentMovementSpeed);
currentRotationSpeed = currentDeltaTime * currentHandInfo.rotationSpeed;
if (currentRotationSpeed > 0) {
currentHandInfo.currentHandRotation = Quaternion.Lerp (currentHandInfo.currentHandRotation, currentHandInfo.handRotation, currentRotationSpeed);
}
currentHandInfo.currentElbowPosition = Vector3.Lerp (currentHandInfo.currentElbowPosition, currentHandInfo.elbowPosition, currentDeltaTime * currentMovementSpeed);
currentHandInfo.currentHandWeight = Mathf.Lerp (currentHandInfo.currentHandWeight, currentHandInfo.handWeight, currentDeltaTime * weightLerpSpeed);
if (currentHandInfo.currentHandWeight < 0.01f) {
currentHandInfo.handPosition = currentHandInfo.noSurfaceHandPosition.position;
currentHandInfo.handRotation = Quaternion.LookRotation (currentTransformForward);
currentHandInfo.elbowPosition = currentHandInfo.noSurfaceElbowPosition.position;
currentHandInfo.currentHandPosition = currentHandInfo.handPosition;
currentHandInfo.currentHandRotation = currentHandInfo.handRotation;
currentHandInfo.currentElbowPosition = currentHandInfo.elbowPosition;
}
}
} else {
currentTransformForward = playerTransform.forward;
for (int j = 0; j < handsToSurfaceInfoListCount; j++) {
currentHandInfo = handsToSurfaceInfoList [j];
currentHandInfo.surfaceFound = false;
currentHandInfo.handWeight = 0;
currentHandInfo.currentHandWeight = 0;
currentHandInfo.handPosition = currentHandInfo.noSurfaceHandPosition.position;
currentHandInfo.handRotation = Quaternion.LookRotation (currentTransformForward);
currentHandInfo.elbowPosition = currentHandInfo.noSurfaceElbowPosition.position;
currentHandInfo.currentHandPosition = currentHandInfo.handPosition;
currentHandInfo.currentHandRotation = currentHandInfo.handRotation;
currentHandInfo.currentElbowPosition = currentHandInfo.elbowPosition;
}
}
}
}
public bool currentWeightInBothHandsEqualTo (float weightValue)
{
int numberOfHands = 0;
for (int j = 0; j < handsToSurfaceInfoListCount; j++) {
if (handsToSurfaceInfoList [j].currentHandWeight == weightValue) {
numberOfHands++;
}
}
if (numberOfHands == 2) {
return true;
}
return false;
}
public override void updateOnAnimatorIKState ()
{
if (adjustHandsToSurfacesEnabled) {
if (!isBusy || smoothBusyDisableActive) {
currentPositionCenter = playerTransform.position + playerTransform.up;
for (int j = 0; j < handsToSurfaceInfoListCount; j++) {
currentHandInfo = handsToSurfaceInfoList [j];
isRightHand = currentHandInfo.isRightHand;
currentHandPosition = currentHandInfo.currentHandPosition;
if (float.IsNaN (currentHandPosition.x)) {
if (isRightHand) {
currentHandPosition.x = rightHandTransform.position.x;
} else {
currentHandPosition.x = leftHandTransform.position.x;
}
}
if (float.IsNaN (currentHandPosition.y)) {
if (isRightHand) {
currentHandPosition.y = rightHandTransform.position.y;
} else {
currentHandPosition.y = leftHandTransform.position.y;
}
}
if (float.IsNaN (currentHandPosition.z)) {
if (isRightHand) {
currentHandPosition.z = rightHandTransform.position.z;
} else {
currentHandPosition.z = leftHandTransform.position.z;
}
}
currentHandPosition.x =
Mathf.Clamp (currentHandPosition.x, currentPositionCenter.x - maxHandsDistance, currentPositionCenter.x + maxHandsDistance);
currentHandPosition.y =
Mathf.Clamp (currentHandPosition.y, currentPositionCenter.y - maxHandsDistance, currentPositionCenter.y + maxHandsDistance);
currentHandPosition.z =
Mathf.Clamp (currentHandPosition.z, currentPositionCenter.z - maxHandsDistance, currentPositionCenter.z + maxHandsDistance);
currentHandInfo.currentHandPosition = currentHandPosition;
currentWeightToApply = currentHandInfo.currentHandWeight;
if (currentWeightToApply > minIKValue) {
currentIKGoal = currentHandInfo.IKGoal;
animator.SetIKRotationWeight (currentIKGoal, currentWeightToApply);
animator.SetIKPositionWeight (currentIKGoal, currentWeightToApply);
animator.SetIKPosition (currentIKGoal, currentHandInfo.currentHandPosition);
animator.SetIKRotation (currentIKGoal, currentHandInfo.currentHandRotation);
animator.SetIKHintPositionWeight (currentHandInfo.IKHint, currentWeightToApply);
animator.SetIKHintPosition (currentHandInfo.IKHint, currentHandInfo.currentElbowPosition);
}
}
}
}
}
public bool playerIsBusy ()
{
return
usingHands ||
!isThirdPersonView ||
playerControllerManager.isPlayerOnFFOrZeroGravityModeOn () ||
(playerControllerManager.isUsingCloseCombatActive () && pauseHandsOnSurfaceIfCloseCombatActive) ||
playerControllerManager.iscloseCombatAttackInProcess () ||
playerControllerManager.isActionActive () ||
adjustHandsPaused ||
playerControllerManager.isUsingJetpack () ||
playerControllerManager.isFlyingActive () ||
playerControllerManager.isSwimModeActive () ||
playerControllerManager.isCarryingPhysicalObject ();
}
public void setWeightLerpSpeedValue (float newValue)
{
weightLerpSpeed = newValue;
}
public void setOriginalWeightLerpSpeed ()
{
setWeightLerpSpeedValue (originalWeightLerpSpeed);
}
public void setAdjustHandsPausedState (bool state)
{
adjustHandsPaused = state;
}
public void setSmoothBusyDisableActiveState (bool state)
{
smoothBusyDisableActive = state;
}
public void setAdjustHandsToSurfacesEnabledState (bool state)
{
adjustHandsToSurfacesEnabled = state;
}
public void enableHandsCheckPausedWithDelayActive (float duration)
{
stopUpdateDelayToResumeStateCoroutine ();
delayToResumeStateCoroutine = StartCoroutine (updateDelayToResumeStateCoroutine (duration));
}
public void stopUpdateDelayToResumeStateCoroutine ()
{
if (delayToResumeStateCoroutine != null) {
StopCoroutine (delayToResumeStateCoroutine);
}
handsCheckPausedWithDelayActive = false;
}
IEnumerator updateDelayToResumeStateCoroutine (float duration)
{
handsCheckPausedWithDelayActive = true;
WaitForSeconds delay = new WaitForSeconds (duration);
yield return delay;
handsCheckPausedWithDelayActive = false;
}
//EDITOR FUNCTIONS
public void setAdjustHandsToSurfacesEnabledStateFromEditor (bool state)
{
setAdjustHandsToSurfacesEnabledState (state);
updateComponent ();
}
void updateComponent ()
{
GKC_Utils.updateComponent (this);
}
#if UNITY_EDITOR
void OnDrawGizmos ()
{
if (!showGizmo) {
return;
}
if (GKC_Utils.isCurrentSelectionActiveGameObject (gameObject)) {
DrawGizmos ();
}
}
void OnDrawGizmosSelected ()
{
DrawGizmos ();
}
void DrawGizmos ()
{
if (showGizmo) {
for (int j = 0; j < handsToSurfaceInfoList.Count; j++) {
Gizmos.color = Color.green;
Gizmos.DrawSphere (handsToSurfaceInfoList [j].handPosition, gizmoRadius);
Gizmos.color = Color.yellow;
Gizmos.DrawSphere (handsToSurfaceInfoList [j].elbowPosition, gizmoRadius);
Gizmos.color = gizmoColor;
Gizmos.DrawSphere (handsToSurfaceInfoList [j].currentHandPosition, gizmoRadius);
Gizmos.DrawSphere (handsToSurfaceInfoList [j].currentElbowPosition, gizmoRadius);
}
}
}
#endif
[System.Serializable]
public class handsToSurfaceInfo
{
public string Name;
public Transform raycastTransform;
public bool useMultipleRaycast;
public List<multipleRayInfo> raycastTransformList = new List<multipleRayInfo> ();
public AvatarIKHint IKHint;
[HideInInspector] public Vector3 elbowPosition;
[HideInInspector] public Vector3 currentElbowPosition;
public bool isRightHand;
public AvatarIKGoal IKGoal;
public float handSurfaceOffset;
public float rayCastDistance;
public float currentHandWeight;
public float movementSpeed;
public float rotationSpeed;
public float walkingMovementSpeed;
[HideInInspector] public bool surfaceFound;
public bool useMinDistance;
public float minDistance;
[HideInInspector]public float currentDistance;
[HideInInspector] public Vector3 multipleRaycastDirection;
[HideInInspector] public int numberOfSurfacesFound;
[HideInInspector] public Vector3 multipleRaycastHitNormal;
[HideInInspector] public Vector3 multipleRaycastHitPoint;
[HideInInspector] public float handWeight;
[HideInInspector] public Vector3 handPosition;
[HideInInspector] public Quaternion handRotation;
[HideInInspector] public Vector3 currentHandPosition;
[HideInInspector] public Quaternion currentHandRotation;
public Transform noSurfaceHandPosition;
public Transform noSurfaceElbowPosition;
}
[System.Serializable]
public class multipleRayInfo
{
public Transform raycastTransform;
public bool surfaceFound;
[HideInInspector] public Vector3 hitPoint;
[HideInInspector] public Vector3 hitNormal;
public float rayCastDistance;
public bool raycastEnabled = true;
}
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: 9cfcfa56079afbc42a6379886d12b52f
timeCreated: 1538062040
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 40995
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
packageVersion: 3.77g
assetPath: Assets/Game Kit Controller/Scripts/Player/Animator IK/handsOnSurfaceIKSystem.cs
uploadId: 814740

View File

@@ -0,0 +1,48 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class simpleIKHand : OnAnimatorIKComponent
{
[Header ("Main Settings")]
[Space]
public bool simpleIKHandActive;
public float IKWeight;
public AvatarIKGoal handIKGoal;
[Space]
[Header ("Components")]
[Space]
public Animator mainAnimator;
public Transform IKPositionTransform;
public override void updateOnAnimatorIKState ()
{
if (simpleIKHandActive) {
mainAnimator.SetIKRotationWeight (handIKGoal, IKWeight);
mainAnimator.SetIKPositionWeight (handIKGoal, IKWeight);
mainAnimator.SetIKPosition (handIKGoal, IKPositionTransform.position);
mainAnimator.SetIKRotation (handIKGoal, IKPositionTransform.rotation);
}
}
public override void setActiveState (bool state)
{
simpleIKHandActive = state;
}
public override void setCharacterElements (GameObject newCharacter)
{
playerComponentsManager currentPlayerComponentsManager = newCharacter.GetComponent<playerComponentsManager> ();
if (currentPlayerComponentsManager != null) {
mainAnimator = currentPlayerComponentsManager.getPlayerController ().getCharacterAnimator ();
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 11d0773023d38d44eb305df5d8dd896d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 40995
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
packageVersion: 3.77g
assetPath: Assets/Game Kit Controller/Scripts/Player/Animator IK/simpleIKHand.cs
uploadId: 814740