A good First Person Controller

Hi! You maybe remember the tutorial I did on creating a basic First Person Controller some time ago. I sat down to finally remedy the problems that this setup had:

1.Instant acceleration - If you press/let go of a movement button the player immediately goes full speed into that direction/stops, which does not feel smooth.
2. Collisions with walls - Since there the Controller simply tells Armory to move the player forward, the physics engine does a sloppy job of dealing with running into walls. It feels jittery and the player can even clip through the wall under some circumstances.
3. Slopes - The worst case scenario of colliding with walls. The Controller moves the player into the sloped surface, only to then be pushed up by the physics engine. Super jittery, and with inconsistent movement speed.
4. Jumping- Not existent. The setup would have allowed for it to be added, but it wouldn’t have been good.

I accomplished all these goals while keeping using Logic Nodes, and I am going to show you the result and the things I learn along the way. This is not going to be a Tutorial, I think you will soon see why.

The funkiness of Armory
You probably know: Armory is not perfect. So there were quite a few unexpected hurdles I had to overcome during the creation of the new Controller. For example, did you know that the execution of Logic scripts is locked at 60 times per seconds? I did not. This results in the game showing you the same result of your Logic for a couple frames if you use on a Monitor with a higher refresh-rate than 60Hz, which I do, and you game runs at more than 60FPS as well. I think this was set up like this so the speed of the logic of the game would stay the same, regardless of its frame rate without any additional setup required. For my purpose I want to tie the “logic rate” to the frame rate, for which I needed to change a bit of Haxe code. Thanks to @BlackGoku36 for helping me find this bit.
In iron/Sources/iron/App.hx line 46 has to be deactivated:

line 46: // kha.Scheduler.addTimeTask(update, 0, iron.system.Time.delta);

and update(); added in line 113. This makes my installation of Armory different than anybody else’s, I hope someone can create a Pull request which adds UI functionality to switch between these two behaviors.
By the way, the value of iron.system.Time.delta is always 1/60. To get the real delta time of the program you need to use iron.system.Time.realDelta;. Of course the Time node uses .delta, so I have to change that as well.
For the program to work I needed to get the position where the Player collided with a wall, so I created a custom node for that. It will be available in logic_pack.

Another thing that left me scratching my head is that reroute knots, aside from being an incredibly useful tool to organize your nodes, sometimes have the side-effect of breaking your program. When using a reroute knot with the modified Time node the value returned by the knot was not the time between frames, no no, it was the time for how long the game has been running for. I have no idea why, all I could do is avoid this case. Similarly when using knots to route the Cast Physics Ray -> Normal output, it sometimes becomes NaN. Again no idea why, just don’t do it.
On the subject of Cast Physics Ray -> Normal, when using this output to calculate something multiple times in one go the time the program needs to calculate the logic drastically increases, the longer this calculation is done the worse it gets Kind of as it would recourse and add a loop every frame. To “fix” this I set the value of a Vector to the value of the Normal once, and then for then keep on calculating everything using this saved Vector.

Creating the Logic
My idea was to keep the whole thing as mathematically as possible, so I have full control over everything that is going on. But I still needed to apply a Rigidbody to the player-object to get information on collisions and to also handle minor bumps on the ground, for which the old method of letting the physics engine push up the Player still works. Every frame the Physics-velocity is set to 0, so any freak collision won’t cause the Player to slide away.
The Player’s input is calculated into a raw movement vector. This already includes smooth acceleration.

Then a ray is cast downwards to figure out if the Player is grounded. If he is, the jump input is looked at and movement takes place. If he is not, “fake gravity” will take place.

Next up the raw movement vector gets rotated so it is parallel to the face the Player is standing on and still pointing into the correct direction.

After that it looks for a collision with a wall and then looks if the movement vector is pointing at the wall. If that is the case, the movement vector is “squished” so it becomes parallel to the wall, and the Player is being moved by that Vector. If not, this the Player is translated by the previous movement vector. The logic also covers the case that the Player is not currently colliding with a wall but will be placed inside one if the current movement vector would be used, as well as a few other edge cases.


Because the vector gets “squished” against the wall its length → the speed of the Player changes, which needs to be updated in the Raw movement Vector.

Of course the Player needs to be slowed down if he is not pressing any movement buttons. That is take care of here:

This also takes care of not slowing the Player down while he is in air.

Maybe you noticed that I multiply Values a bunch of times by Time → Delta. I do this to keep the speed of the Player constant, regardless of the frame rate of the game.

Downsides of this Controller

  1. It currently requires a modified version of Armory.
  2. This setup is only suitable in very static environments. Because the Physics-velocity is set to zero every frame the Player can not be pushed around by moving objects, including moving platforms.

Here is the .blend if you want to take a look at it yourself. You can use it if you want to, just remember to modify your Armory installation. FPS.blend (1.5 MB) Video

5 Likes

Hello @Simonrazer,

As much as I like your good FPS node setup, It is quite complicated. Such an elaborate node-setup for a good FPS controller means there is something wrong with Armory3d, specifically the Physics engine. You almost do not use any physics at all in the whole setup, not even real gravity. Why is that the case? and why did you not use the “Set Velocity” node? I intend to rectify any physics related issues, so I need some pointers to know what exactly is wrong.

Thank you in advance.

1 Like

Unfortunately not providing a good character controller out-of-the-box is a running theme with Physics engines, at least with physx and bullet. They do provide some kind of kinematic character controller for starting up but usually they have a lot of issues and you basically end up rewriting your own to fit in your game.
What I meant by all of that is that is not unusual to write your controller from the ground up because they require a lot of refinement. And such requirements usually don’t fit rigid bodies right, because of collision resolution and other stuff. So you might end up using very little of the actual engine physics when creating a character controller for certain type of games.

bindings for a kinematic character controller existed in previous versions of armory but it had a few different issues that you couldn’t change easily because those were “inherited” from the original c++ version. I’ve seen that last years the kinematic controller has been updated in Bullet repo but it would require an update on armory part to check if it’s really worth it instead of just using very limited features of rigid bodies, or none at all.

3 Likes

I agree with what you say about “certain types of games”. But, for most of the usual FPS games, accurate FPS control must be possible with a lot simpler physics nodes, or at least that is what I think. By usual games I mean, character to be able to accelerate and decelerate, climb and decent on ramps/slopes, Jump and also step on and stay on moving platforms. This is all possible using very simple node setup, correct weights, gravity and friction setting of rigid bodies.

What exactly do you mean by “Collision Resolution” ?

By collision resolution I mean this https://en.wikipedia.org/wiki/Collision_response. The collision resolution of Bullet’s rigidbodies is very problematic with ramps/slopes, so even something so simple as going up / going down / jumping on a ramp can be quite tricky to pull off with the right feeling to it using rigidbodies.

1 Like

To make the whole thing much simpler by using only physics Nodes Armory would need to have a magically good Physics engine, which does not exist. I tried using Set Velocity and even Apply Force, but a) using Set Velocity does not make things simpler in this case at all b) Apply Force makes things even more complicated. This is the case because in the end it always feels better to calculate the direction the Player should be moving compared to brute-force pushing the Player the way he wants to go and the having the Physics engine make up something useful of that.

1 Like

Sorry to resurrect such an old post but I’m currently looking for a solution like this where I can tweak a well-defined player controller setup.

Namely I’m having the issue where I notice how easy it is to scale walls with the vast majority of player control set ups. Simply pressing into the wall was allowing the player to defy gravity. I’m ok with speed runners break my games, but not everyone! XD

I’m having some trouble however as several nodes are broken in this. I would just grab version 2020.1, but I can’t seem to find it anywhere. That way I could have in theory check the original setup.

Any help trying to update this would be appreciated…

EDIT: I’m actually finding these screenshots to be incredibly helpful!

I’ve already gone and replaced a couple of nodes by using this as a guide… maybe If I got stuck or find a solution I’ll post the new blend here.

Ahh man! what is this node?

image

This is how it looks currently in 2023.6:

image

EDIT:

Actually the screenshots help for re-establishing lost node connections, but I’m really struggling to understand the names because of the size of the screenshots.

Perhaps someone can just flick me a copy of Armory 2020.1?

EDIT:

Well I tried my best to restore this one but some of these sections of nodes illuded me.
But I did manage to fix the node tree enough to fix the runtime error. Now You can play the game but the player is just slowly rising and you can’t do anything.

I’ll upload what I’ve worked on in case someone else wants to help:

FPS_2023.6.blend (2.0 MB)

Anyone want to take it from here?

Im impressed the .blend even opens in current Armory! I looked at it again last year and things were a total mess already
I think the broken Node in your SC is the one Node i had to add, it also returns the Coordinates of where a Physics collision happens.
I actually have a semi-working version of Armory 2020, working as in I can see the nodes, but most the Haxe stuff is a total mishmash of versions. Here it is armsdkALT.7z - Google Drive (remeber, you also need an old version of Blender, at least i strongyl suspect so)
Also, here is my try from last year to get it working in newer versions. The FPS controller is different tho, as I added Push Forces (for Boost Pads/Jump Mines) and Gravity changes. I dont remember which version of Armory it was, but it opens in Blender with Armory version 2022.11
FPSREV.blend (3.5 MB)

1 Like

Thanks for this Simon! All of this helps to increase my confidence with FPS logic in Armory.

Cool with this version I seem to be able to load the nodes for a better look.

But, from what you’re saying I might be getting the most out of deconstructing pieces of this rather than using it all and trying to fix it.

Just wondering if you could by chance could send me a copy of 2022.11? It’s… murderously difficult trying to find very specific versions of Armory from the past.

Closest I could get was sourceforge: armory download | SourceForge.net

-S

Yup, got that one armsdk.7z - Google Drive

1 Like

Cool, thanks so much!

Btw, I should have asked earlier but let me know what kind of license you have for your work? Happy to give credit if need be.

-S

Öh never thought about it, I’ll say its cool if you give me credit somewhere, if you use it comercially/rebundel it somehow ask me again

1 Like

It’s… murderously difficult trying to find very specific versions of Armory from the past.

You can download SDK versions with support for Blender versions >= 2.8 (I guess starting in 2018 or 2019) by cloning the armsdk repository with Git and then checking out the version tag you need. For older versions of the SDK it’s more difficult (if not impossible) since they required custom Blender builds and I don’t think they are public anymore…

2 Likes

Ahh I totally missed the versions on that GitHub repository. Thanks for pointing that out :slight_smile:

1 Like