Flying better character control

Hi all,

I managed to control my character walking on the ground and jumping using BetterCharacterControl.
My questions are : is it normal that the CollisionShape affected to the character doesn’t rotate when calling control.setViewDirection () ?
When I set setViewDirection, the character only rotates across Y axis, how can we rotate across other axes ?

Thanks for any advice :slight_smile:

1 Like

Yes, that is normal behavior. The collision shape should always be aligned with the gravity vector, and the controlled spatial should only rotate around the gravity vector.

If you want the visible character to be able to rotate around other axis, you can add the BetterCharacterControl to a node, then attach the character spatial to the node. The BetterCharacterControl will force the node to only rotate around the gravity vector, but the character spatial will be free to rotate however you wish.

2 Likes

@takyon Have your questions been adequately answered?

Yes, but I don’t know if it matches my request, because when my character jumps, I would like to apply to him linear velocity, so that he acts like a rigid body (I missed this detail in my first psot).

Is there a way to switch between two controls for a spatial ? Or should I do like codex said, knowing that I tried but didn’t succed to make it work.

Maybe I could enable/disable the two controls to do the switch ? but I don’t know if it could affect perfoirmances.

1 Like

You could factor that force into the walk direction. If I remember correctly BetterCharacterControl just sets the xz linear velocity directly from the walk direction.

Alternatively, you could write your own character control from scratch. Since a character is basically a rigid body with angular factors disabled, it isn’t actually as difficult as it may sound. Though, it might be a little overkill for this. :slightly_smiling_face:

1 Like

Maybe I could enable/disable the two controls to do the switch ?

Yes, you could do that. A disabled control has almost no performance impact.

I also like codex’s idea of writing your own character control. BetterCharacterControl would provide a good starting point.

1 Like

Yes, I think rewriting the BetterCharacterControl class could give me a better understanding of the engine, thanks for your answers :slight_smile: @codex

2 Likes