private void Update() { if (enemy.currentState == EnemyState.Dead) { return; } if (enemy.seePlayer) { if (!sawPlayer) { sawPlayer = true; wasAtSpawn = false; } if (enemy.CheckAttackDistance()) { move.StopMoving(); enemy.Attack(); } else { if (enemy.currentState != EnemyState.Attack && enemy.currentState != EnemyState.Hurt) { enemy.currentState = EnemyState.Chasing; move.Move(enemy.GetDirectionToPlayer()); } } } else { if (sawPlayer) { StartCoroutine(CalmDownCo()); } var checkedDistanceToSpawn = move.CheckDistanceToTarget(spawnPoint, 1f); if (!checkedDistanceToSpawn && !sawPlayer && !wasAtSpawn) { enemy.currentState = EnemyState.Patrolling; move.Move(move.GetDirectionToTarget(spawnPoint, true) * 0.5f); } else if (checkedDistanceToSpawn && !sawPlayer && !wasAtSpawn) { wasAtSpawn = true; } else if (!sawPlayer && wasAtSpawn) { Patrolling(); } else { enemy.currentState = EnemyState.Idle; move.StopMoving(); } } }
private void BaseLogic() { if (CheckAttackDistance()) { move.StopMoving(); Attack(); } else { move.Move(GetDirectionToPlayer()); } }
protected void UpdateMove() { if (!moveableObject) { return; } Vector3 tryMove = Vector3.zero; if (Input.GetKey(KeyCode.LeftArrow)) { tryMove += Vector3Int.left; } if (Input.GetKey(KeyCode.RightArrow)) { tryMove += Vector3Int.right; } if (Input.GetKey(KeyCode.UpArrow)) { tryMove += Vector3Int.up; } if (Input.GetKey(KeyCode.DownArrow)) { tryMove += Vector3Int.down; } if (tryMove != Vector3.zero) { moveableObject.Move(tryMove); } }
/// <summary> /// Prevent the controller from having control when the MoveToTarget coroutine is updating. /// </summary> /// <returns>Should the RigidbodyCharacterController continue execution of its Move method?</returns> public override bool Move() { // Return early if the character isn't in move position yet. if (!m_InPosition) { return(false); } // The movement direction can be restricted. var relativeInputVector = m_Controller.RelativeInputVector; if (!m_AllowHorizontalMovement) { relativeInputVector.x = 0; } if (!m_AllowForwardMovement) { relativeInputVector.z = 0; } // Determine the amount of force to apply to the move object. The amount of Root Motion force will determine how much force to apply. var force = m_Controller.transform.TransformDirection(relativeInputVector) * m_Controller.RootMotionForce.magnitude * m_MoveForce; // Stop moving forward if the object cannot be moved anymore. This will happen if the object runs into a wall. if (!m_MoveableObject.Move(force)) { m_Controller.InputVector = Vector3.zero; } m_Controller.RootMotionForce = Vector3.zero; return(true); }
public void manipulatObject() { if (canManipulate) { moveableobj.Move(transform.position); } }
protected override void Update() { base.Update(); if (isOpened && !move.CheckDistanceToTarget(openPosition.position, 0.1f)) { move.Move(move.GetDirectionToTarget(openPosition.position, false)); DisableInteract(); } else if (!isOpened && !move.CheckDistanceToTarget(closedPosition.position, 0.1f)) { move.Move(move.GetDirectionToTarget(closedPosition.position, false)); DisableInteract(); } else { move.StopMoving(); EnableInteract(); } }