janhohenheim / foxtrot

The all-in-one Bevy 3D game template for desktop.
Apache License 2.0
629 stars 45 forks source link

fix character capsule size issue #329

Open xx1adfasd opened 2 months ago

xx1adfasd commented 2 months ago

In project Foxtrot, the capsule of the fox should be in fact a lying down cylinder. Because its an quadruped animal.

So in fact in the code the height is the length of the fox, and the radius is a half of the height of the fox.

Also, the radius of the capsule need to be multiplied by the scale_y.

There's no visual changes in the game. Open "Foxtrot Dev" window and toggle Colliders rendering on to see the difference.

Also if the pull was merged, I assume that "HEIGHT" should be renamed to "LENGTH" later on.

janhohenheim commented 2 months ago

You are of course correct. I intentionally use a capsule here because I expect most users to want a humanoid character. The fox is more of a placeholder. I see two possibilities:

Not sure what the best course of action is. I'm leading a bit towards the latter right now, but I'll have to think about it.

xx1adfasd commented 2 months ago

After some thinking, I think the best we can do here, as a template project should do, is to support every cases.

Suppose someone want to make a game with a human AND a fox, like the fox being his pet etc. Then there's need for character capsule for both humanoid and quadruped characters.

So, we can basically make an enum to mark which kind of model did our model use, then past it into CharacterControllerBundle.

And also Global number HEIGHT and RADIUS will then not be the best way. We can then write the number in the game setting file, like what we currently did in assets/config/config.game.toml

enum CharacterCapsuleKind{
    X, // lying, the head is facing X
    Y, // upward, like a human
    Z // lying, the head is facing Z
}

//...
let z_kind = CharacterCapsuleKind::Z;
let fox_bundle = CharacterControllerBundle::new(z_kind, height, radius)

and the code of new will handle the FloatHeight assignment work (if lying, radius*scale_y is the FloatHeight, if Y upward, the capsule_height*scale_y is FloatHeight and capsule_height = body_height - 2 * radius (remember the height we passed in is half height of the capsule, and the capsule_height is the length of the cylinder without the two half spheres ))

By the way, if this method is adopted, we then maybe in fact actually put a human model in the game as a showcase. I think the mixamo Robot is good to go. (Imagine a Robot NPC who can talk to the fox to give some information)