Third person 8 directional movement system (also for upbge 0.3.0)

Hello,

You get the third person movement system (8 directional) including my keybindings script.

Added:

  • a converted version for UPbge (28-2-2019)

Controls:
K - open the keybindings menu
WSAD - move
SPACE - jump
mouse - lookaround
scrollwheel - zoom
left shift - run

BGE:
Tera movement system.blend (762 KB)

UPBGE:
8 directional movement system(upbge).blend (785.4 KB)

- For upbge 3.0 download upbge version and change player_camera.py line 27 to 31 into:
(Setting Keybinds DO NOT work in upbge 0.3.0, default keys can be set inside the script)

        x = (int(render.getWindowWidth()/2)/render.getWindowWidth())-logic.mouse.position[0]
        y = (int(render.getWindowHeight()/2)/render.getWindowHeight())-logic.mouse.position[1]

I hope you like it,
Cotax

3 Likes

Wow that is really cool. Nice work. Can I make the player blend between the different directions?

 Can I make the player blend between the different directions

Go to my_functions.py lookup face_direction(): and set turn speed between 0.0-1.0

Ok, Thanks!

Thanks again.

What version of blender was this made in?
It’s having problems on 2.78 for me.
Thanks.

in version 2.76 i thought it was, but this one should not give any problems, i am still using it myself (adapted version but the base it the same). What problems do you have?

Edit: and what version of blender do you use? it runs fine in 2.78a
Edit2: Runs fine in 2.78c as well

A good example and scripts, thank you! :yes:

Why do you use an additional object for the sensor “ground_chesk” and type - Collision? Is not it easier to create a “Ray” sensor on the player itself, or is it better to transfer it to a script?

Tera movement system-edit.blend (758 KB)

And when running through an external player, the player and camera are shifted to the right - 2.78с

Why do you use an additional object for the sensor “ground_chesk” and type - Collision? Is not it easier to create a “Ray” sensor on the player itself

Everyone has its own way, but rays cast from origin, so standing on a ledge while the origin is not on it (so 1/3 of the player stands on a edge) the player will stop reacting because the ray wont get into positive state.

another reason, the movement feels heavier this way, while climbing and walking angles.

physics bunny hop problem is solved with the sensor as well look at here:

and here i solved the problem

some like rays, in this case you need rays to be cast from 5 points, center and 4 corners of the player, a sensor well you put it there and it works, not much work and look at tha last movie you see how it reacts to slopes as well, no flying etc just relaxed walking up and down, no bouncing either.

And when running through an external player, the player and camera are shifted to the right - 2.78с

the blend you uploaded has nothing wrong, works as it should here.

but if you got shifting problem i bet you moved the character, the camera is on slow parent, if you move it all cam settings will be off. in order to move em you select the camera empty go to objects tab in properties panel, scroll down to relation extras and turn of slow parent.

1 Like

Added:

  • a converted version for UPbge

Hi there. I’ve tried this setup with my game, and it works great up until planet gravity is added in. The player block just stutters and can’t move with the surface of the planet. I have a hunch it’s with the camera. Maybe change it so that it has the option to rotate with the player so that it can work with artificial gravity setups like mine.

If you want to troubleshoot this, my setup is as follows:

  • Make a new scene and go to the Scene tab. Set the gravity there to 0.

  • Paste the player setup into the new scene.

  • Add a new game property to the “player” object (doesn’t matter which type) and name it “gravity”

  • Add a UV Sphere below it. Make it static and give it a spherical collision box. Give it the float property “gAmount” and type in a number (this is the gravity constant, I use 9.8)

  • Add an “Always” logic sensor with true level pulse triggering and a “Python” actuator.

  • Make said actuator use this script:

from bge import logic
from mathutils import Vector

cont = logic.getCurrentController()
own = cont.owner
scene = logic.getCurrentScene()

for obj in scene.objects:
    if "gravity" in obj:
        
        pull = Vector(obj.getVectTo(own)[1])
        pull.magnitude = own["gAmount"]
        obj.applyForce(pull)

player = scene.objects["player"]
align = own.getVectTo("player")[1]
player.alignAxisToVect(align,2,0.5)

You should see that the player stutters erratically as it tries to walk around the sphere’s circumference.

Hmm i see,
unfortunately i need to say this script is not compatible with planetary gravity.

The problem here is the calculation of the direction vector(where player needs to look at if you press a key) and the function face_direction() in my_functions.py, it also aligns the player to get his head back up.

uncomment that line in face_direction and set the vec_x and vec_y in player.py to own.blabla and if you press w it will act like you want but now you can’t rotate the player or set it’s direction anymore.

I suggest for now to try and use deadalus his setup, i believe he said it’s compatible with planetary gravity. I will look at this issue an other time and see if i can make it compatible.

- For upbge 3.0 download upbge version and change player_camera.py line 27 to 31 into

        x = (int(render.getWindowWidth()/2)/render.getWindowWidth())-logic.mouse.position[0]
        y = (int(render.getWindowHeight()/2)/render.getWindowHeight())-logic.mouse.position[1]

Hey Cotaks,
Thanks a lot for your work on this template & making it available.

In Upbge 0.2.5b the render.enableMotionBlur lines seems to be causing all movement and physics in the scene to cease. The player object won’t move.

Commenting out this line in the In the settings.py script solves the problem.

Hmm that is strange works perfectly fine here(just tested). Did you change something by accident? Or what error do you get if you look into the console window(window → toggle system console)?

Also you can delete that line or the whole settings.py from your file if wanted, it’s not tied to any script and i didn’t even know i had it in there.

Nope didn’t change anything. Just tested the fresh file again to make sure.

The console has this error Error: could not open '/home/myuser/Documents/8 directional movement system(upbge).bgeconf', which if I understand correctly is just due to the bge globalDict file not existing before saving the keybindings.

Maybe the problem is specific to some detail of my system, I’m thinking it’s probably the graphics card, since it’s the motion blur function that’s triggering the problem.

I’m on Linux Mint 20.3 Cinnamon, running Intel i7-7820HQ & Quadro M2200 Mobile graphics.

indeed that error is just a notice that there isn’t a save file to load

That could be it indeed, you can remove the line, but the game engine itself should have it on by default anyway, so it’s a bit strange.

Hmm, might be some strange error in that bit of code in the game engine.

I appreciate your prompt replies to this. Thanks.