public static bool MatchTarget(this Animator animator, Transform target, AvatarTarget avatarTarget, float startNormalizedTime, float targetNormalizedTime) { if (animator.runtimeAnimatorController == null) { return(false); } if (animator.isMatchingTarget) { return(false); } if (animator.IsInTransition(0)) { return(false); } MatchTargetWeightMask weightMask = new MatchTargetWeightMask(Vector3.one, 1f); animator.MatchTarget( target.position, target.rotation, avatarTarget, weightMask, startNormalizedTime, targetNormalizedTime ); return(true); }
private void DoMatchTarget() { if (this._animator == null || this._animator.IsInTransition(0)) { return; } Vector3 vector = Vector3.zero; Quaternion quaternion = Quaternion.identity; if (this._transform != null) { vector = this._transform.position; quaternion = this._transform.rotation; } if (!this.targetPosition.IsNone) { vector += this.targetPosition.Value; } if (!this.targetRotation.IsNone) { quaternion *= this.targetRotation.Value; } MatchTargetWeightMask weightMask = new MatchTargetWeightMask(this.positionWeight.Value, this.rotationWeight.Value); this._animator.MatchTarget(vector, quaternion, this.bodyPart, weightMask, this.startNormalizedTime.Value, this.targetNormalizedTime.Value); }
static int _CreateMatchTargetWeightMask(IntPtr L) { int count = LuaDLL.lua_gettop(L); if (count == 2) { Vector3 arg0 = LuaScriptMgr.GetNetObject <Vector3>(L, 1); float arg1 = (float)LuaScriptMgr.GetNumber(L, 2); MatchTargetWeightMask obj = new MatchTargetWeightMask(arg0, arg1); LuaScriptMgr.PushValue(L, obj); return(1); } else if (count == 0) { MatchTargetWeightMask obj = new MatchTargetWeightMask(); LuaScriptMgr.PushValue(L, obj); return(1); } else { LuaDLL.luaL_error(L, "invalid arguments to method: MatchTargetWeightMask.New"); } return(0); }
private void HandleLedgeStepMotion(PlayerController player) { AnimatorStateInfo animState = player.Anim.GetCurrentAnimatorStateInfo(0); AnimatorTransitionInfo transInfo = player.Anim.GetAnimatorTransitionInfo(0); if (!waitingBool && isRootMotion && animState.IsName("Idle")) { player.EnableCharControl(); isRootMotion = false; } else if (waitingBool && (animState.IsName("StepUp_Hlf") || animState.IsName("StepUp_Qtr") || animState.IsName("StepUp_Full"))) { waitingBool = false; player.UseRootMotion = true; Vector3 targetPosition = ledgeInfo.Point + ledgeInfo.Direction * 0.24f; Quaternion targetRotation = Quaternion.LookRotation(ledgeInfo.Direction); MatchTargetWeightMask weightMask = new MatchTargetWeightMask(Vector3.one, 1f); player.Anim.MatchTarget(targetPosition, targetRotation, AvatarTarget.Root, weightMask, 0.1f, 0.9f); } else if (transInfo.IsName("AnyState -> StepUp_Hlf") || transInfo.IsName("AnyState -> StepUp_Qtr") || transInfo.IsName("AnyState -> StepUp_Full")) { player.UseRootMotion = false; } }
void DoMatchTarget() { if (_animator == null) { return; } Vector3 _pos = Vector3.zero; Quaternion _rot = Quaternion.identity; if (_transform != null) { _pos = _transform.position; _rot = _transform.rotation; } if (!targetPosition.IsNone) { _pos += targetPosition.Value; } if (!targetRotation.IsNone) { _rot *= targetRotation.Value; } MatchTargetWeightMask _weightMask = new MatchTargetWeightMask(positionWeight.Value, rotationWeight.Value); _animator.MatchTarget(_pos, _rot, bodyPart, _weightMask, startNormalizedTime.Value, targetNormalizedTime.Value); }
// // Constructor // public AnimatorMatchTarget(Animator animator) { m_animator = animator; //m_matchTargetRange = new Vector2(m_startMatchTime, m_endMatchTime); m_matchTargetRange = new Vector2(0.1f, 0.2f); m_weightMask = new MatchTargetWeightMask(m_positionXYZWeight, m_rotationWeight); }
void Update() { if (animator.GetCurrentAnimatorStateInfo(0).IsName("Vault")) { MatchTargetWeightMask mask = new MatchTargetWeightMask(Vector3.one, 0f); animator.MatchTarget(wallHandPosition.position, wallHandPosition.rotation, AvatarTarget.LeftHand, mask, takeOffTime, handDownTime); } }
public void ResetPosition() { var animator = GetComponent <Animator>(); var mask = new MatchTargetWeightMask(Vector3.one, 0); var time = animator.GetCurrentAnimatorStateInfo(0).normalizedTime; animator.MatchTarget(Vector3.zero, Quaternion.identity, AvatarTarget.Root, mask, time, time + 0.01f); }
/// <summary> /// Cache the component references and initialize the default values. /// </summary> protected override void Awake() { base.Awake(); m_Rigidbody = GetComponent <Rigidbody>(); m_HeightChange = GetComponent <HeightChange>(); m_MatchTargetWeightMask = new MatchTargetWeightMask(Vector3.one, 0); }
/// <summary> /// Cache the component references and initialize the default values. /// </summary> protected override void Awake() { base.Awake(); m_Rigidbody = GetComponent <Rigidbody>(); m_Hang = GetComponent <Hang>(); m_Swim = GetComponent <Swim>(); m_MatchTargetWeightMask = new MatchTargetWeightMask(Vector3.one, 0); }
// Update is called once per frame void Update() { isMatching = animator.isMatchingTarget; if (match && !isMatching) { mask = new MatchTargetWeightMask(matchWeight, rotWeight); match = false; animator.MatchTarget(target.transform.position, target.transform.rotation, avT, mask, startTime, endTime); } }
public override void Trigger(GameObject actor) { Animator animator = actor.GetComponent <Animator>(); if (animator == null) { return; } MatchTargetWeightMask weightMask = new MatchTargetWeightMask(Vector3.one, 0); animator.MatchTarget(target.transform.position, target.transform.rotation, avatarTarget, weightMask, startTime, targetTime); }
void DoMatchTarget() { Vector3 _pos = Vector3.zero; Quaternion _rot = Quaternion.identity; if (_transform != null) { _pos = _transform.position; _rot = _transform.rotation; } _pos += targetPosition.value; _rot *= targetRotation.value; MatchTargetWeightMask _weightMask = new MatchTargetWeightMask(positionWeight.value, rotationWeight.value); agent.MatchTarget(_pos, _rot, bodyPart.value, _weightMask, startNormalizedTime.value, targetNormalizedTime.value); }
//**********************************************************************************// // MATCH TARGET // // call this method to help animations find the correct cursorObject // // don't forget to add the curve MatchStart and MatchEnd on the animation clip // //**********************************************************************************// void MatchTarget(Vector3 matchPosition, Quaternion matchRotation, AvatarTarget target, MatchTargetWeightMask weightMask, float normalisedStartTime, float normalisedEndTime) { if (animator.isMatchingTarget) { return; } float normalizeTime = Mathf.Repeat(animator.GetCurrentAnimatorStateInfo(0).normalizedTime, 1f); if (normalizeTime > normalisedEndTime) { return; } if (!ragdolled) { animator.MatchTarget(matchPosition, matchRotation, target, weightMask, normalisedStartTime, normalisedEndTime); } }
public static int constructor(IntPtr l) { int result; try { Vector3 positionXYZWeight; LuaObject.checkType(l, 2, out positionXYZWeight); float rotationWeight; LuaObject.checkType(l, 3, out rotationWeight); MatchTargetWeightMask matchTargetWeightMask = new MatchTargetWeightMask(positionXYZWeight, rotationWeight); LuaObject.pushValue(l, true); LuaObject.pushValue(l, matchTargetWeightMask); result = 2; } catch (Exception e) { result = LuaObject.error(l, e); } return(result); }
static int get_rotationWeight(IntPtr L) { object o = LuaScriptMgr.GetLuaObject(L, 1); if (o == null) { LuaTypes types = LuaDLL.lua_type(L, 1); if (types == LuaTypes.LUA_TTABLE) { LuaDLL.luaL_error(L, "unknown member name rotationWeight"); } else { LuaDLL.luaL_error(L, "attempt to index rotationWeight on a nil value"); } } MatchTargetWeightMask obj = (MatchTargetWeightMask)o; LuaScriptMgr.Push(L, obj.rotationWeight); return(1); }
public override void OnEnter() { if (!UpdateCache(Fsm.GetOwnerDefaultTarget(gameObject))) { Finish(); return; } if (cachedTarget != target.Value) { cachedTarget = target.Value; targetTransform = cachedTarget != null ? cachedTarget.transform : null; } weightMask = new MatchTargetWeightMask(); DoMatchTarget(); if (!everyFrame) { Finish(); } }
private void DoMatchTarget() { if (!(_animator == null)) { Vector3 matchPosition = Vector3.zero; Quaternion matchRotation = Quaternion.identity; if (_transform != null) { matchPosition = _transform.position; matchRotation = _transform.rotation; } if (!targetPosition.IsNone) { matchPosition += targetPosition.Value; } if (!targetRotation.IsNone) { matchRotation *= targetRotation.Value; } MatchTargetWeightMask weightMask = new MatchTargetWeightMask(positionWeight.Value, rotationWeight.Value); _animator.MatchTarget(matchPosition, matchRotation, bodyPart, weightMask, startNormalizedTime.Value, targetNormalizedTime.Value); } }
static int set_positionXYZWeight(IntPtr L) { object o = LuaScriptMgr.GetLuaObject(L, 1); if (o == null) { LuaTypes types = LuaDLL.lua_type(L, 1); if (types == LuaTypes.LUA_TTABLE) { LuaDLL.luaL_error(L, "unknown member name positionXYZWeight"); } else { LuaDLL.luaL_error(L, "attempt to index positionXYZWeight on a nil value"); } } MatchTargetWeightMask obj = (MatchTargetWeightMask)o; obj.positionXYZWeight = LuaScriptMgr.GetNetObject <Vector3>(L, 3); LuaScriptMgr.SetValueObject(L, 1, obj); return(0); }
protected override void OnInitialize() { weightMask = new MatchTargetWeightMask(positionXYZWeight.normalized, rotationWeight); }
public virtual void MatchTarget(Vector3 matchPosition, Quaternion matchRotation, AvatarTarget target, MatchTargetWeightMask weightMask, float normalisedStartTime, float normalisedEndTime) { if (anim.isMatchingTarget || anim.IsInTransition(0)) { return; } float normalizeTime = Mathf.Repeat(anim.GetCurrentAnimatorStateInfo(0).normalizedTime, 1f); if (normalizeTime > normalisedEndTime) { return; } anim.MatchTarget(matchPosition, matchRotation, target, weightMask, normalisedStartTime, normalisedEndTime); }
public void AnimMatchTarget(Vector3 matchPosition, Quaternion matchRotation, AvatarTarget target, MatchTargetWeightMask weightMask, float normalisedStartTime, float normalisedEndTime) { animator.MatchTarget(matchPosition, matchRotation, target, weightMask, normalisedStartTime, normalisedEndTime); }
private static void INTERNAL_CALL_MatchTarget(Animator self, ref Vector3 matchPosition, ref Quaternion matchRotation, AvatarTarget targetBodyPart, ref MatchTargetWeightMask weightMask, float startNormalizedTime, float targetNormalizedTime){}
public override void Update(PlayerController player) { AnimatorStateInfo animState = player.Anim.GetCurrentAnimatorStateInfo(0); AnimatorTransitionInfo transInfo = player.Anim.GetAnimatorTransitionInfo(0); right = Input.GetAxisRaw(player.Inputf.horizontalAxis); if (isInCornering || isOutCornering) { if (animState.IsName("InCornerLeft") || animState.IsName("CornerLeft") || animState.IsName("CornerRight") || animState.IsName("InCornerRight")) { player.UseRootMotion = true; MatchTargetWeightMask mask = new MatchTargetWeightMask(Vector3.one, 1f); player.Anim.MatchTarget(cornerTargetPosition, cornerTargetRotation, AvatarTarget.Root, mask, 0f, 1f); return; } else if (animState.IsName("HangLoop")) { isOutCornering = isInCornering = false; player.UseRootMotion = true; } else { return; } } else if (isClimbingUp) { if (animState.IsName("Idle") || transInfo.IsName("ClimbUp -> Idle")) { player.StateMachine.GoToState <Locomotion>(); } return; } if (Input.GetKeyDown(player.Inputf.crouch)) { LetGo(player); return; } // Adjustment for moving platforms RaycastHit hit; if (Physics.Raycast(player.transform.position + Vector3.up * (player.HangUpOffset - 0.1f), player.transform.forward, out hit, 1f, ~(1 << 8), QueryTriggerInteraction.Ignore)) { if (hit.collider.CompareTag("MovingPlatform")) { MovingPlatform moving = hit.collider.GetComponent <MovingPlatform>(); moving.AttachTransform(player.transform); } } if (right != 0f) { LookForCorners(player); } AdjustPosition(player); player.Anim.SetFloat("Right", right); player.Anim.SetBool("isOutCorner", isOutCornering); player.Anim.SetBool("isInCorner", isInCornering); if (Input.GetKey(player.Inputf.jump) && animState.IsName("HangLoop")) { if (ledgeDetector.CanClimbUp(player.transform.position, player.transform.forward)) { ClimbUp(player); } } }
void DoMatchTarget() { MatchTargetWeightMask weightMask = new MatchTargetWeightMask(positionWeight.Value, rotationWeight.Value); animator.MatchTarget(matchPosition.Value, Quaternion.Euler(matchRotation.Value), bodyPart, weightMask, startNormalizedTime.Value, targetNormalizedTime.Value); }
public override void Update(PlayerController player) { AnimatorStateInfo animState = player.Anim.GetCurrentAnimatorStateInfo(0); AnimatorTransitionInfo transInfo = player.Anim.GetAnimatorTransitionInfo(0); right = Input.GetAxisRaw(player.Inputf.horizontalAxis); if (isInCornering || isOutCornering) { if (animState.IsName("InCornerLeft") || animState.IsName("CornerLeft") || animState.IsName("CornerRight") || animState.IsName("InCornerRight")) { player.UseRootMotion = true; MatchTargetWeightMask mask = new MatchTargetWeightMask(Vector3.one, 1f); player.Anim.MatchTarget(cornerTargetPosition, cornerTargetRotation, AvatarTarget.Root, mask, 0f, 1f); return; } else if (animState.IsName("HangLoop")) { isOutCornering = isInCornering = false; player.UseRootMotion = true; } else { return; } } else if (isClimbingUp) { if (animState.IsName("Idle") || transInfo.IsName("ClimbUp -> Idle")) { player.StateMachine.GoToState <Locomotion>(); } return; } if (Input.GetKeyDown(player.Inputf.crouch)) { LetGo(player); return; } AdjustPosition(player); if (right != 0f) { LookForCorners(player); } player.Anim.SetFloat("Right", right); player.Anim.SetBool("isOutCorner", isOutCornering); player.Anim.SetBool("isInCorner", isInCornering); // Test for climbing up key hold times if (animState.IsName("HangLoop")) { if (Input.GetKey(player.Inputf.jump) && jumpHeldFor < HANDSTAND_HOLD_TIME) { jumpHeldFor += Time.deltaTime; } else if (Input.GetKeyUp(player.Inputf.jump) || jumpHeldFor >= HANDSTAND_HOLD_TIME) { Vector3 tryClimbTo = ledgeInfo.Point + player.transform.forward * player.CharControl.radius; if (UMath.CanFitInSpace(tryClimbTo, player.CharControl.height, player.CharControl.radius)) { ClimbUp(player); } } } }
override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { weightMask = new MatchTargetWeightMask(positionWeight, rotationWeight); }
/// <summary> /// Automatically adjust the <c>GameObject</c> position and rotation. /// </summary> /// <param name="matchPosition">The position we want the body part to reach.</param> /// <param name="matchRotation">The rotation in which we want the body part to be.</param> /// <param name="targetBodyPart">The body part that is involved in the match.</param> /// <param name="weightMask">Structure that contains weights for matching position and rotation.</param> /// <param name="startNormalizedTime">Start time within the animation clip (0 - beginning of clip, 1 - end of clip).</param> /// <param name="targetNormalizedTime">End time within the animation clip (0 - beginning of clip, 1 - end of clip), values greater than 1 can be set to trigger a match after a certain number of loops. Ex: 2.3 means at 30% of 2nd loop.</param> public void MatchTarget(Vector3 matchPosition, Quaternion matchRotation, AvatarTarget targetBodyPart, MatchTargetWeightMask weightMask, float startNormalizedTime, float targetNormalizedTime = 1);
public override void MatchTarget(Vector3 matchPosition, Quaternion matchRotation, AvatarTarget target, MatchTargetWeightMask weightMask, float normalisedStartTime, float normalisedEndTime) { if (animator.isMatchingTarget || animator.IsInTransition(0)) { return; } float normalizeTime = Mathf.Repeat(animator.GetCurrentAnimatorStateInfo(0).normalizedTime, 1f); if (normalizeTime > normalisedEndTime) { return; } if (GetComponent <PhotonView>().IsMine == true) { animator.MatchTarget(matchPosition, matchRotation, target, weightMask, normalisedStartTime, normalisedEndTime); GetComponent <PhotonView>().RPC("AnimMatchTarget", RpcTarget.Others, matchPosition, matchRotation, target, weightMask, normalisedStartTime, normalisedEndTime); } }
public void Process(params object[] data) { if (animator == null) { return; } switch (action) { case ActionType.Enable: animator.enabled = true; break; case ActionType.Disable: animator.enabled = false; break; case ActionType.SetParameter: switch (parameterType) { case AnimatorEventData.ParameterType.Boolean: animator.SetBool(parameterName, booleanValue); break; case AnimatorEventData.ParameterType.Float: animator.SetFloat(parameterName, floatValue); break; case AnimatorEventData.ParameterType.Integer: animator.SetInteger(parameterName, integerValue); break; case AnimatorEventData.ParameterType.Trigger: animator.SetTrigger(parameterName); break; } break; case ActionType.CrossFade: animator.CrossFadeInFixedTime(targetState, transitionDuration, -1, targetStateOffset); break; case ActionType.MatchTarget: if (matchTarget != null) { var weightMask = new MatchTargetWeightMask { positionXYZWeight = weightMaskPositionWeight, rotationWeight = weightMaskRotationWeight, }; animator.MatchTarget(matchTarget.position, matchTarget.rotation, avatarTarget, weightMask, startTime, endTime); } break; case ActionType.Play: animator.PlayInFixedTime(targetState, -1, targetStateOffset); break; case ActionType.SetIK: if (ikPositionRef != null) { animator.SetIKPosition(avatarIkGoal, ikPositionRef.position); animator.SetIKPositionWeight(avatarIkGoal, ikPositionWeight); } if (ikRotationRef != null) { animator.SetIKRotation(avatarIkGoal, ikRotationRef.rotation); animator.SetIKRotationWeight(avatarIkGoal, ikRotationWeight); } if (lookAtRef != null) { animator.SetLookAtPosition(lookAtRef.position); animator.SetLookAtWeight(lookAtWeight, bodyWeight, headWeight, eyesWeight, clampWeight); } break; case ActionType.SetLayerWeight: animator.SetLayerWeight(targetLayer, layerWeight); break; } }
public void MatchTarget(Vector3 matchPosition, Quaternion matchRotation, AvatarTarget targetBodyPart, MatchTargetWeightMask weightMask, float startNormalizedTime){}