public Locomotion(GameObject character, float rotationSpeed, float jumpHeight, Transform viewTransform, AnimationCurve movementVectorBlend, AnimationCurve rotationBlend, ICharacterInput characterInput, IMover characterMover) { _characterGameObject = character; _characterMover = characterMover; _viewTransform = viewTransform; _RotationSpeed = rotationSpeed; _jumpHeight = jumpHeight; _MovementVectorBlend = movementVectorBlend; _RotationBlend = rotationBlend; _characterInput = characterInput; _RootMotionDelta = _characterGameObject.GetComponentInChildren <RootMotionDelta>(); _locomotionMode = LocomotionMode.Idle; if (_RootMotionDelta != null) { _RootMotionDelta.OnRootPositionChange += HandleRootMotion; } //Rotate Character to Desired Forward called _RotateLocomotionEvents = _characterGameObject.GetComponentsInChildren <IRotateDesiredForwardEvent>(); if (_RotateLocomotionEvents.Length > 0) { for (int i = 0; i < _RotateLocomotionEvents.Length; i++) { _RotateLocomotionEvents[i].OnCallDesiredForwardRotationChange += MoveToDesiredForward; } } UseMovementAngleDifference = true; OnStateChange?.Invoke(_state); }
public void stopMoving() { _agent.isStopped = false; _agent.updateRotation = false; locomotionMode = LocomotionMode.MODE_STOPPED; _parent.Animacao.SetBool("run", false); _parent.Animacao.SetBool("walk", false); }
//--------------------------------------------- public void startRunning() { _agent.isStopped = false; locomotionMode = LocomotionMode.MODE_RUNNING; _parent.Animacao.enabled = true; _parent.Animacao.SetFloat("value_WalkingSpeed", 1); _parent.Animacao.SetBool("walk", false); _parent.Animacao.SetBool("run", true); }
//--------------------------------------------- public void startWalking() { _agent.isStopped = false; _agent.updateRotation = true; locomotionMode = LocomotionMode.MODE_WALKING; _parent.Animacao.enabled = true; _parent.Animacao.speed = 1; _parent.Animacao.SetFloat("value_WalkingSpeed", 1); _parent.Animacao.SetBool("run", false); _parent.Animacao.SetBool("walk", true); // makeOneRotationStep(_parent.preferedPosition); }
void Update() { if (Input.GetKeyDown(KeyCode.Space)) // Press space to change locomotion mode { if (locomotionMode == LocomotionMode.Teleporter) { locomotionMode = LocomotionMode.ArmSwinger; } else { locomotionMode = LocomotionMode.Teleporter; } } }
private void SendAnimatorLocomotionCommands(bool isRunning) { var movementMagnitude = Mathf.Clamp(_movementInput.magnitude, 0, 1); int runModifierAddition = isRunning ? 2 : 0; Vector3 runcomposite = DesiredCharacterVectorForward.normalized * runModifierAddition; Vector3 baseMovementComposite = (DesiredCharacterVectorForward.normalized * movementMagnitude); finalMovementComposite = runcomposite + baseMovementComposite; var runGap = 0.00f; var walkGap = 0.00f; if (_locomotionMode == LocomotionMode.Run) { walkGap = -0.1f; runGap = -0.1f; } else if (_locomotionMode == LocomotionMode.Walk) { walkGap = 0.1f; runGap = -0.1f; } var finalMovementCompositeMagnitude = finalMovementComposite.magnitude; if (finalMovementCompositeMagnitude >= runThreshold + runGap && finalMovementCompositeMagnitude <= sprintThreshold) //run { _locomotionMode = LocomotionMode.Run; } else if (finalMovementCompositeMagnitude > sprintThreshold + Mathf.Epsilon) //sprint { _locomotionMode = LocomotionMode.Sprint; } else if (finalMovementCompositeMagnitude < runThreshold + walkGap && finalMovementCompositeMagnitude > 0.01f) //walk { _locomotionMode = LocomotionMode.Walk; } else { _locomotionMode = LocomotionMode.Idle; } OnMoveAnimatorSpeedChange?.Invoke((float)_locomotionMode); movementSpeed = (int)_locomotionMode; }
void Start() { teleportAreas = FindObjectsOfType <DungeonTeleportArea>(); if (GetArg("-locomotion") != null) { var locomotionArg = GetArg("-locomotion"); if (locomotionArg == "armswinger") { locomotionMode = LocomotionMode.ArmSwinger; } else if (locomotionArg == "teleport") { locomotionMode = LocomotionMode.Teleporter; } } SwitchLocomotionMode(); }
private void fixThoseOutsideNavmesh() { if (_agent.FindClosestEdge(out hitNav)) { if ((!float.IsInfinity(hitNav.position.x) && !float.IsNegativeInfinity(hitNav.position.x)) && (!float.IsInfinity(hitNav.position.y) && !float.IsNegativeInfinity(hitNav.position.y)) && (!float.IsInfinity(hitNav.position.z) && !float.IsNegativeInfinity(hitNav.position.z))) { transform.position = Vector3.MoveTowards(transform.position, hitNav.position, 0.02f * Time.deltaTime); transform.position = hitNav.position; _agent.SetDestination(parent.target); //Debug.DrawLine(transform.position, transform.position + Vector3.up * 50, Color.grey); if (indexListaCorrigidos < 5) { listaPontosCorrigidos[indexListaCorrigidos] = hitNav.position; } indexListaCorrigidos++; if (indexListaCorrigidos == 5) { bool bTodosiguais = true; foreach (Vector3 p in listaPontosCorrigidos) { if (p != listaPontosCorrigidos[0]) { bTodosiguais = false; } } if (bTodosiguais) { locomotionMode = LocomotionMode.OUTSIDE_NAVMESH;//Se o GajoCitizen.FixedUpdate detectar isto remove o caracter } } } } if (indexListaCorrigidos > 5) { indexListaCorrigidos = 0; } }
public void SetLocomotionMode(int lm) { if (currentLocomotionMode != (LocomotionMode)lm) { if (currentLocomotionMode == LocomotionMode.NONE) { teleportButton.interactable = !((LocomotionMode)lm == LocomotionMode.TELEPORT); walkButton.interactable = !((LocomotionMode)lm == LocomotionMode.WALK); } else { teleportButton.interactable = currentLocomotionMode == LocomotionMode.TELEPORT; walkButton.interactable = currentLocomotionMode == LocomotionMode.WALK; } currentLocomotionMode = (LocomotionMode)lm; // Disable Creation Mode onButton.interactable = true; offButton.interactable = false; currentCreationMode = CreationMode.NONE; } }
// Use this for initialization void Start() { currentSelectionMode = SelectionMode.CLICK; currentLocomotionMode = LocomotionMode.TELEPORT; }