unity – I’m trying to create a hierarchical state machine, but don’t understand how to transition to a superstate

I have a CharacterController that implements a StateMachine that uses a number of states and transitions. The StateMachine checks for a valid transition to a new state at the start of every frame, and either moves to a new state or continues ticking the current state. Here is a brief example of all of this working together:

public class CharacterController : MonoBehaviour
{
    public StateMachine { get; private set; } 
    
    private void Awake()
    {
        InitializeStateMachine();
    }

    private void Update()
    {
        StateMachine.Tick(); // Checks for valid transitions, and then sets and/or ticks the appropriate state
    }

    private void InitializeStateMachine()
    {
        StateMachine = new StateMachine();

        // Create states
        var idleState = new IdleState(this);
        var walkState = new WalkState(this);
        var jumpState = new JumpState(this);

        // Add some transitions
        Func<bool> idleToWalk() => () => IsGrounded && velocity.x != 0;
        Func<bool> idleToJump() => () => IsGrounded && Input.GetKeyDown(Keycode.Space);

                                   // From       To       Condition
        StateMachine.AddTransition(idleState, walkState, idleToWalk());
        StateMachine.AddTransition(idleState, jumpState, idleToJump());
    }
}

I really like this implementation because the states and the StateMachine are decoupled; only the “motor” class knows about both of these things, which makes it very easy for me to keep my code clean.

However, as my project grows I’m running into an issue where I’m having to create many transitions to states that share similar functionality. For example, the idle and walk states only work if my controller is grounded, so if I have a fall state then I need to make transitions from the fall state to every possible grounded state:

Func<bool> fallToIdle() => () => IsGrounded && velocity.x == 0;
Func<bool> fallToWalk() => () => IsGrounded && velocity.x != 0;
Func<bool> fallToSlide() => () => IsGrounded && velocity.x != 0 && Input.GetButtonDown("Slide");

It would be nicer if I could simply transition to some kind of generic GroundedState that handles the next steps as needed.

I read that one way to help solve this problem is to create a hierarchical state machine, but, though the concept makes sense to me, I don’t understand how to implement it in the context of my current system.

I assume that I would need to make a GroundedState parent class from which any ground states inherit, but how do I actually make transitions from fall to grounded, and then get from grounded to, for example, walk or slide in a single frame? Would the GroundedState need a reference to the StateMachine class so that it can set the correct substate accordingly?

dungeon world – How can a player smoothly transition from death to playing a hireling?

When a you roll last breath “On a miss, your fate is sealed. You’re marked as Death’s own and you’ll cross the threshold soon. The GM will tell you when.”

Sometimes, the fictional positioning can allow you to keep the character alive until the end of the session, though they are marked for death and in a bad shape. It can be made known to the players that the character will officially die at the end of the session.

Sometimes, though, it may be more difficult because they somehow died early in the session or there is no satisfying way to handwave their death temporarily.

This is where my question comes in: some people let the play switch POV to a hireling but how do you do that in a satisfying way?

Hirelings don’t have a character sheet. Do you draw up a sheet mid-session? If you use the stats from the hireling (Warrior, Burglar etc.) how do they map to the usual player stats for basic moves? Do they have a class?

How do I merge two photos with a transition from the color photo to the black-and-white photo?

Just to provide a third option – & you can do this with just one colour photo, no need for a separate black & white image.

Add a Hue/Saturation adjustment layer & dial out all the saturation.
Then, just like xenoid’s example, paint half the layer mask out & you’re left with half colour, half black & white.

enter image description here

The great thing about using masks for any task like this is you can keep changing your mind – paint bits in, then paint them out again, until you’re happy.

stochastic processes – How to understand the transition density of reflected Brownian motion

enter image description here

We can see from the above picture the transition density of reflecting Browninan motion is given by (19). As we know, the first part ($2p(t,x,y)$) is the transition density of a Brownian motion (from $x$ to set $y$) and the second part($2p(t,-x,y)$) also is the transition density of a Brownian motion (from $-x$ to set $y$).

  1. My first question is the figure. $p_t(x,E)$ should equal $p(t,x,y)$ + $p(t,-x,y)$, but why in the figure the area of the shadow denoting $p_t(x,E)$ looks larger than the sum of those denoting $p(t,x,y)$ and $p(t,-x,y)$?
  2. Why does the transition density (19) represent the rerflected Brownian motion at barrier 0? The connection among them is not so obvious. In particular, how to explain these two parts? why the sum of these two transition densities represent a modulus Brownian motion, where can I see it?

How to develop a interleaving transition system with 3 parallel programs

Up until now, Ive learnt how to design a transition system using 2 program graphs. But I am looking for researches on this approach with 3 program graphs. I cant seem to find any online resources to help me with this approach.

I have been able to draw out the 3 program graphs separately but am struggling with the interleaving process using the formula

PG($_i$) = ($Loc_i$, $Act_i$, $Effect_i$, →i, $Loc_0$,$_i$, $G_0$,$_i$)

I am struggling with what the interleaved program graph is meant to look like before it is converted into a transition system.

the 3 parallel programs are:

x:=4x-2
x:=12x+4
x:=6x/2 

Could someone please point me in the right direction? not necessarily complete the program graph.

precision and accuracy – DiscreteMarkovProcess: preparing the transition matrix and unexpected negative results

I would like to implement a Markov process.
It consists on a walk on a one-dimensional lattice, with nodes spaced $epsilon$ from $-2$ to $2$.
The transition probabilities for $x neq y$ are as follows:

begin{equation}
p(x,y) = begin{cases}
frac{1}{2} , text{if} ,, y= xpm epsilon ,, text{and} ,,f(y) < f(x) \
frac{1}{2} exp Big(-(f(y)-f(x)) ,/ betaBig) , text{if} ,, y= xpm epsilon ,, text{and} ,,f(y) > f(x) \ 0 ,, text{else}
end{cases},.
end{equation}

where $beta$ is a given number and $f(x) = frac{x^4}{4}-frac{x^2}{2}$. For $x=y$, probabilites will be computed by ensuring row sums equal to $1$.

I constructed the probability matrix as follows:

f(x_):= (1/4) x^4- (1/2) x^2
neighRight(beta_, eps_) := 
Table(If(f(-2 + (i)*eps) > f(-2 + (i - 1)*eps), (1/2)*
Exp(-(f(-2 + (i)*eps) - f(-2 + (i - 1)*eps))/beta),  1/2 ), {i, 
2*2/eps})
neighLeft(beta_, eps_) := 
Table(If(f(-2 + (i - 1)*eps) > f(-2 + (i)*eps), (1/2)*
Exp(-(f(-2 + (i - 1)*eps) - f(-2 + (i)*eps))/beta),  1/2 ), {i, 
2*2/eps})
diagonal(beta_, eps_) := 
Join({1/2}, 
Table(1 - neighRight(beta, eps)((i + 1)) - 
neighLeft(beta, eps)((i)), {i, 2*2/eps - 1}), {1/2})
TransMatrix(beta_, eps_) := 
SparseArray({Band({1, 1}) -> diagonal(beta, eps), 
Band({2, 1}) -> neighLeft(beta, eps), 
Band({1, 2}) -> neighRight(beta, eps)}, {1 + 2*2/eps, 
1 + 2*2/eps});

So, the functions neighRight and neighLeft provide the elements to the right and left respectively of the main diagonal, which is then computed via the homonymous function using the condition that the sum of the values over the row should equal $1$. The transition matrix is tridiagonal so SparseArray comes in handy.

I am sure there are better, more efficient and elegant, ways to do it and I would be grateful for any suggestions on how to assemble the transition matrix.

Nevertheless, it seems to give me the result I am looking far, after quite some “manual” checking.

Next I generate start and target distributions, such as

start = ConstantArray(0, 41) ;
end = ConstantArray(0, 41) ;
start((31)) = 1;
end((11)) = 1;

again, surely a caveman man to do it, but I wish the process to start on node $31$ and I am interested in the mean hitting time to node $11$.

  A = DiscreteMarkovProcess(start, TransMatrix(0.06, 0.1));
  EscTime = FirstPassageTimeDistribution(A, end);
  Mean(EscTime)
  3.9774*10^18

which seems reasonable. The fact, is I lower the first argument of the TransMatrix function, called $beta$ above, by just a tad, e.g.

  A = DiscreteMarkovProcess(start, TransMatrix(0.06, 0.1));
  EscTime = FirstPassageTimeDistribution(A, end);
  Mean(EscTime)
  -4.54097*10^16

I get a negative mean hitting time, which should not be I believe. Ultimately the transition matrix seems perfectly legitimate, cannot understand what the issue is.

Could it be something to do with the very small numbers generated by the exponentials, whose argument is divided by $beta$, as the latter is lowered plenty? I am at loss as to how to fix this, thanks.

graphics3d – Animate smooth transition between viewpoints with ViewProjection -> “Orthographic”

I’m looking for code to animate smooth transition between 2 viewpoints with ViewProjection -> "Orthographic". My first attempt is below but it’s missing some scale invariance

enter image description here

th = Thickness(0.0015);
arrows = Graphics3D({Arrowheads(0.02), th, 
    Arrow({{1, 0, 0}, {-1, 0, 0}}), Arrow({{0, 0, -1}, {0, 0, 1}}), 
    Arrow({{0, 1, 0}, {0, -1, 0}})});
plane = Plot3D(0, {x, -1, 1}, {y, -1, 1}, PlotStyle -> None, 
   Mesh -> 5, MeshStyle -> Directive(Thickness(.001), Opacity(.2)), 
   BoundaryStyle -> Directive(th, Opacity(.2)));

graph = Plot3D({2/((Pi) Sqrt((1 + x - y) (1 - x + y))), 0}/
    10, {x, -1, 1}, {y, -1, 1}, 
   RegionFunction -> 
    Function({x, y}, 0.9 <= x + y <= 1 && -1 <= x - y <= 1), 
   PlotRange -> {{-1, 1}, {-1, 1}, {0, .5}}, Filling -> 0, 
   FillingStyle -> Yellow, Mesh -> None, PlotPoints -> 50, 
   BoundaryStyle -> th, AspectRatio -> 1, Axes -> None, 
   Boxed -> False);
graphic3d = Show(arrows, plane, graph);

animateTransition(object_, t_, point1_, point2_) := Module({},
   angle = t*(Pi)/2;
   Show(graph, arrows, plane, 
    ViewPoint -> point1*Cos(angle) + point2*Sin(angle), 
    ViewProjection -> "Orthographic")
   );
(* to get initial direction use 
https://mathematica.stackexchange.com/questions/132228/how-to-obtain-
the-viewpoint/132231 *)
startDirection = {1.17091, -2.65552, 1.73988}; 
endDirection = {-1, -1, 0};
pics = Table(
   animateTransition(graphic3d, t, startDirection, endDirection), {t, 
    0, 1, .1});
ListAnimate(pics)

How did you transition from being laid off to self-employed?

Discussion in ‘Self Improvement and Being Successful’ started by Gwenworks, Jul 28, 2021 at 3:38 PM.


  1. Gwenworks


    Gwenworks




    uix_expand



    uix_collapse

    New Member


    Joined:
    Thursday
    Messages:
    3
    Likes Received:
    0

    Struggling to pull everything after I was laid off. Finding a job in the middle of the pandemic is a real struggle. I have read so many articles on how to start earning money online and what skills to learn. But it seems there is nothing that sparks my interest. I am not interested either to work on something that is related to my previous job because what appeals to me is learning new that will eventually lead to a new career. I got stuck in finding my niche! Any thoughts? Thank you.

     

    #1


    Gwenworks,
    Jul 28, 2021 at 3:38 PM

Share This Page

The same transition twice in Pushdown automata (PDA)

If we want to design a PDA that accepts all words those the first half equals reverse of the second half and there is a ‘#’ between them, “ab#ba” for example.

We start push each letter we read and when we read the symbol ‘#’ don’t push it and start popping from its next letter and check for match between the current letter and the top of the stack.

But what do we if there is no ‘#’ symbol in the center of the string, can we do the same of usual NFA ?

I mean can we make same transitions twice, each one to distinct state ?

Example :
let us be in the state ‘q1’, when I read the letter make a transition to the state q2 and pop the top of the stack and make a transition to the state q3 without pop ?

unity – Gizmos disappear after a scene transition

I have used OnDrawGizmos function to draw some cubes. If I run the project from that particular scene, the gizmos are visible. But after a scene transition they disappear. It appears again if I select the Gamobject that contains my script with the OnDrawGizmos function.

I tried adding the Selection.activeGameObject and it worked but I can’t build my project because unity editor is being involved in my scipt. Adding a Editor folder and keeping my scipt there does not allow me to drag and drop the script to the hierachy, so that I can attach the relavant gameobject that should be active.

I also tried #if UNITY_EDITOR … #endif, but after building the app, the app still did not show the gizmos on my phone.

Please can anyone let me know a way to stop gizmos from disappearing.