Differences between "Orient Rotation to Movement" and "Use Controller Desired Rotation" Unreal Engine 4

These are two options in the CharacterMovementComponent in UE4 (My current version is 4.15.3).

You probably won’t see much difference for AI-controlled characters, but for your player character the difference is this:

“Orient Rotation to Movement”: Your character will turn to face the direction of travel. No matter which way the camera is facing, your character will always face the direction in which he or she is moving.

“Use Controller Desired Rotation”: Your character will orient to the direction of the controller rotation. In most games, this is visually represented by the direction of the camera so your character’s back is always to the camera and he or she rotates to match when the camera is swung. Of course, you can decouple your camera from following the control rotation as well so a more accurate description is that the character will face whichever direction the “right stick” or “Mouse X” is pointing.

Again, you don’t control the AI so both of these options look identical to a third party. I think “Orient Rotation to Movement” looks more natural, but there’s really no big difference, visual or otherwise, for the AI.

The idea is from a post in the Unreal Engine Forums. Here is the link.

Difference between “Orient Rotation to Movement” and “Use Controller Desired Rotation”

Unreal Engine 4 AIController::SetFocus

From this link

AIController.SetFocus is used to keep AI controlled pawn rotated towards given actor or point in space. There are a few priorities of focus points, allowing easy creation of e.g. scripted overrides. For example:

1. AI is moving and path following automatically sets intermediate destination as focal point with low priority (EAIFocusPriority::Move). AI’s pawn is facing forward as it moves around.

2. AI receives a target and sets it as focal point with higher priority (EAIFocusPriority::Gameplay). Pawn starts facing toward target as it keeps moving.

3. Level script forces AI to look at specific point, setting it as even higher priority (EAIFocusPriority::LastFocusPriority + 1, usually defined by project as something more readable…). Pawn rotates toward this point.

4. Movement stops, pawn still looks at whatever script told it to.

5. Script clears forced focus point, pawn rotate towards most important focal point, which is right now target.

6. Target is cleared, pawn keeps current rotation since there’s no focal points to look at.

Set Up Navmesh Invokers In Unreal Engine 4.15

Sometimes our map is very big so we don’t want to generate navmesh for the whole map to reduce the cost.

We can use navmesh invokers to only generate navmesh around the NPCs so they can still move around.

Firstly, we need to go to change Project Settings->Engine->Navigation Mesh->Runtime Generation to Dynamic.

Secondly, we go to Project Settings->Navigation System and check Generate Navigation Only Around Navigation Invokers.

Then, we need to put a navigation volume into the level and make sure it encapsulate the place where we want navmesh to be generated.

At last, we open our npc actor, add a Navigation Invoker component to it.

And register navigation invoker in the event begin play.

 

DFS Search Algorithm

//
//  DFS.cpp
//  Game AI Programming
//
//  Created by Mat Buckland Programming Game AI by Example p238
//

#include "DFS.hpp"

template <class graph_type>

bool Graph_SearchDFS<graph_type>::Search ()
{
    // create a std stack of pointers to edges
    std::stack<const Edge*> stack;

    // create a dummy edge and put on the stack
    // m_iSource is the start position
    Edge Dummy (m_iSource, m_iSource, 0);

    stack.push (&Dummy);

    // while there are edges on the stack keep searching
    while (!stack.empty ())
    {
        // grab the next edge
        const Edge* Next = stack.top ();

        // remove the edge from the stack
        stack.pop ();

        // make a note of the parent of the node this edge points to
        // this is for getting the path after the search
        m_Route[Next->To] = Next->From ();

        // and mark it visited
        m_Visited[Next->To ()] = visited;

        if (Next->To () == m_iTarget)
        {
            return true;
        }

        // push the edges leading from the node this edge points to onto
        // the stack (provided the edge does not point to a previously visied node)
        graph_type::ConstEdgeIterator ConstEdgeItr (m_Graph, Next->To ());

        for (const Edge* pE = ConstEdgeItr.begin (); !ConstEdgeItr.end (); pE = ConstEdgeItr.next ())
        {
            if (m_Visited[pE->To ()] == unvisited)
            {
                stack.push (pE);
            }
        }
    }

    // no path
    return false;
}

std::list<int> Graph_SearchDFS<Graph>::GetPathToTarget () const
{
    std::list<int> path;

    if (!m_bFound || m_iTarget < 0) return path;

    int nd = m_iTraget;

    path.push_back (nd);

    while (nd != m_iSource)
    {
        nd = m_Route[nd];

        path.push_back (nd);
    }

    return path;
}