Gun Wall Leaning in BGE

So this question is out of curiosity and future referencing…

So I planned on adding a wall leaning mechanics for my game. You know? You’re against a wall and you have to peak at a corner?

Something like this:

I just used this as an example.

How can I achieve this?

put a plane, have the plane use it’s orientation,

use a ray from player looking for plane, and if angle is right and ray is hitting engage

(so you mark corners with a invisible plane with a property)

using a raycast only on that collision layer is quite efficient
(check upbge collisiongroup bitmask)

So I add a property for a corner(corner), then I add a ray sensor on X-Ray mode looking for that property?

So what should I do after it detects the corner and I engage?

EDIT: I apparently got i, but it’ll set it to peek left when it detects a corner. So it made me ask this:

Is there a way we could do this using Python? I’ve used Python and it seems to work efficiently. So I might revert to using Python.

logic, python, use whatever works but yes, you can detect the output of the sensor and use that in your logic.


raySensor.hitObject.worldOrientation.col[0] vs own.worldOrientation[0] should help

(so planes only work when the player is facing the same direction or within a angle as the planes orientation)

So how would I set up the script? Sorry for asking, I’m horrible when it comes to setting up scripts…

Also, where do I apply the script?

there are a number of ways to do this, ranging from easiest by offsetting camera relative position to a complex ik rig procedural animation


if ray.positive:
   cam.worldPosition = offset(left or right base on user input)

you could also just be really simple and use two different properties ‘corner_left’ and ‘corner_right’ Since the player raycasting would also probably adhere to casting left and right as well you would be fine just using this.

So from what I’ve been hearing, I know there should be three properties. There should be a “WallCollide”, “CornerLeft”, and a “CornerRight” property. I know if the “WallCollide” property is true, the player just remains the same, but the gun raised up.

Then I know if there’s a corner nearby(containing a CornerLeft or CornerRight property), the property of either corner is true. So once those two properties are true, you press the shoot or aim button and it peeks over the corner.

I’ll try to improvise a script here:

import bge

scene = logic.getCurrentScene()
owner = logic.getCurrentController().owner
armature = scene.objects['PlayerRig']

wallCollide = cont.sensors['WallCollide']

#Peeking left

if wallCollide.positive:
    if owner["CornerLeft"] == True:
        armature.playAction(PlayerCornerPeek, 0, 5)

#Peeking Right

if wallCollide.positive:
    if owner["CornerRight"] == True:
        armature.playAction(PlayerCornerPeek, 10, 15)

Is there a certain way to detect a corner?

I’m trying to refrain from using invisible planes, since that would consume a lot of time…

it may be faster to just parent a ‘left’ propertized empty to the left armature and a ‘right’ to the right armature and use the near sensor…using empties would make the near sensor not so expensive…the way I understand it, it checks all the verts on a model…an empty however only really consists of one vertex(figuratively speaking a single point in 3D space) I use them for exactly this purpose when I need to use a near sensor.

Well, thanks! Your idea worked, with the two sensors…

So thanks to your guy’s support, I’ve made something that no one else has made!

Here’s a blend file, even though it’s a bit glitchy:

Let me know of how I can fix these if you want me to fix them…


PlayerCornerPeek.blend (562 KB)

Glad it worked out…sometimes the easiest method can be the fastest and easiest to implement

Python seems easier, when it comes to interaction of properties from multiple objects…