Single face of a mesh detects collision?

In my game i have a charakter that’s supposed to play an animation when he falls to the ground. I have a Hitbox, but this hitbox also detects a collision when I run at a wall, for example. So, is there a way to only make the bottom face of my hitbox detect collisions? For example by different materials…?!?

You can use Material Collision. (change it from object to material in the sensor’s settings)

You can change between Property and Material… but this means that only faces with a specific material ARE detected. but I want a face with a specific material TO detect! :confused:

The way I do it is by placing another smaller hitbox just below the character, with sensor mode in physics properties.
Then detect collisions on this hitbox.

The trick is to make this sensor object just a little bit smaller than the players collision mesh so it cannot touch walls. It has to be slightly smaller, to much and the bottom part of the players collision mesh could cause the character to ‘sit’ on edges (of platforms for example) without being able to move. Because of course the idea is that the player will only move when the sensor object detects something.

This may sound ridiculous but this is the best method I can think of. It’s guaranteed it will always work. The method of assigning properties is limited. For example, a platform could be a ‘wall’ or a ‘floor’, but never both.

Edit: Also what works really great is to make the players collision mesh thinner at the bottom. The sensor object at the bottom then could be as wide as the bottom of the players collision mesh, but at the same time it will never touch the wall, unless the wall is a slope. Search the right balance to even determine which angle will prevent the player to go forward (and up).

Edit 2: Also it’s better not to have a square collision box. Rounded on the bottom as well as on the sides will give smoother motion when colliding with walls and floors.

Is there a reason you don’t want to have the ground as a separate object to the walls?

Of course, at least if you want to have platforms in your game. The sides of a platform are vertical, so this is a wall. The top is horizontal, so that’s a floor.

I think the best way is use a ray heading straight towards the ground.

Make it so it runs just below the hit box of the player. It works like a dream if setup properly.

Also, as Raco mentioned before, your hit box shouldn’t be rectangular. What works best, for me at least, is a cone-ish shape (vertex at the feet).

@ Linkxgl: With a ray at the bottom you’ll only detect something at that spot. Unless the collision box of the player is sharp at the bottom (like a spike) it will get stuck on edges and bumps on the floor. This was my experience with this technique, unless I’m wrong about the technique. What are your thoughts on that?

Why fake.anything…

This is off-topic, but I’ll respond quickly. As the clip illustrates the method you are using gives far from realistic results. But actions on the display mesh can be animated as realistic as you want, and on top of that there’s room for ‘character’ animation. In other words, faking is the way to go if you want to be creative.

I use sensors around the bounding box for those things. I only use the collision box to prevent the player from going out of bounds.

Example: If the bottom sensor’s property reports ON, then the armature plays X animation.

Let’s say the sensor detects that the character is higher on the floor than it should be so that triggers another property that waits for the impact.

This would be my approach too.

Raco, you’re right, there’s a point at the bottom of the collision box so the player doesn’t get stuck.

I use rays for ground detection because it gives more control.

Collisions only really tell you what the player is hitting.

Rays tell you more: Where and what the player is hitting and the normal of the surface the player is hitting.
Which is useful if you think about it!

If I wanted to lock the player to the ground to prevent sliding, I could. If I wanted to check for a steepness of the ground, I could.

Also, I think rays are less CPU intensive (which is negligible if you’re making a simple game). In this case, it’s just a 3D Vector starting from the player and pointing towards the world -Z axis.

You can parent a empty to the foot bone, and cast rays from that?

This ray can be used to tell if your touching the ground or not?

How would one change the casting direction based on velocity? (Moving down, cast down)

Yes, rays are of course necessary for such things as getting the material of the polygon beneath the player (for virtual friction for example).

@ BPR: to your last question:

from bge import logic
from logic import getCurrentController
from mathutils import Vector

tic_rate = logic.getLogicTicRate()
own = getCurrentController().owner

ray_start = own.worldPosition + own.worldLinearVelocity / tic_rate
ray_end = ray_start + Vector((0, 0, -1))