idanarye / bevy-tnua

A floating character controller for Bevy
https://crates.io/crates/bevy-tnua
Apache License 2.0
235 stars 16 forks source link

How can i create a custom builtin without forking/hacking this whole crate ? #52

Closed ethereumdegen closed 6 months ago

ethereumdegen commented 6 months ago

How can i create a custom builtin without forking/hacking this whole crate ?

I would like to create a custom builtin in my own code, just by importing sub-modules of this crate. However many of them that i (most likely) need are private or private private.

Is there an example of how i can create a custom builtin easily? I want a builtin for hover/fly/climb

idanarye commented 6 months ago

First, to get the terminology out of the way - "custom builtin" is an oxymoron. The "builtin" part in the name of TnuaBuilinWalk and friends is to indicate that these movement commands are built into Tnua - as opposed to custom movement commands that the user can create.

So what you are trying to make is custom movement commands - or, more specifically, custom basis and/or custom actions.

Now, the whole basis/action system was designed to allow users (or, more likely, third party crates) create their own basis and actions (okay, that's not exactly accurate - the original goal was to allow organizing the code for the various movement commands without having to use huge types and functions. But user customization was always an important goal of Tnua). So in theory you should be able to impl TnuaBasis or impl TnuaAction for your own types, and if you can't then this is a bug that I'll need to fix.

What have you tried, and what did you get stuck on?

idanarye commented 6 months ago

Also, do you mind if I move this to Discussions? It feel like its going to be more of a Q&A thing (though I may end up adding things to the code, if it turns out it's not as extendable as I thought)

ethereumdegen commented 6 months ago

well i tried that but look

image

ethereumdegen commented 6 months ago

These squiggly red lines are what im talking about. These are preventing me from making a custom basis without forking and hacking up the whole crate

idanarye commented 6 months ago

I see...

Okay, I won't move this to discussions because there really are some things I need to change.

idanarye commented 6 months ago

bevy_tnua_physics_integration_layer is a crate you need to add as a dependency. I can stand to re-export it if it'll make things easier (or maybe just re-export its math module?)

Wait, I think I already do that:

pub use bevy_tnua_physics_integration_layer::data_for_backends::*;
pub use bevy_tnua_physics_integration_layer::*;

So I just need to change the builtin movement commands' code to import from there.

idanarye commented 6 months ago

@ethereumdegen Can you try the fix-52-improve-extensibility branch? I think you'll have to use all the Tnua crates from there. I'm not 100% about the syntax, but I think if you just give them the proper name it'll look for subcrates inside the workspace:

[dependencies]
bevy-tnua = { git = "https://github.com/idanarye/bevy-tnua", branch = "fix-52-improve-extensibility" }
# Use the proper physics backend, of course:
bevy-tnua-xpbd3d = { git = "https://github.com/idanarye/bevy-tnua", branch = "fix-52-improve-extensibility" }
ethereumdegen commented 6 months ago

okay thanks that makes more sense i kind of fixed w OG branch except i reimplemented ProjectionPlaneForRotation and the Math typs (vector3, float) for now . I will dive in to your branch too.

My new deps look like this :

use super::math::{Vector3,Float,AdjustPrecision}; //reimplemented myself for now use bevy_tnua::TnuaBasisContext;

use bevy::prelude::*; use bevy_tnua::TnuaMotor;

//use bevy_tnua::util::ProjectionPlaneForRotation; // need to remake myself use bevy_tnua::{TnuaBasis, TnuaVelChange};

idanarye commented 6 months ago

Did you try fix-52-improve-extensibility? It exports bevy_tnua::util so you can use my implementation of ProjectionPlaneForRotation, and it reexports math as bevy_tnua::math so you can use that (note that it's only needed if you want to support both f32 and f64. Which you probably would for a third party library, but if you are making an actual game you'd want to pick one or the other)

If that branch works for you, I can make a release tomorrow (I still want to write docs for bevy_tnua::util if it's going to be public)

idanarye commented 6 months ago

@ethereumdegen I've added some more changes to fix-52-improve-extensibility to make it easier to use (these things were previously intended for internal usage only). Please check if it satisfies your code's needs before I merge it and make a release.

idanarye commented 6 months ago

The more I think about it, the more I hate the idea of making ProjectionPlaneForRotation public. I only ever create it for the identity orientation, and it's probably going to break for non-standard orientation. Which I should probably remove (I've opened #53) for that.

If the orientation is standard, rotation_to_set_forward could just be a standalone function.

idanarye commented 6 months ago

@ethereumdegen Version 0.17 is out, and should have everything you need.