[Feature Request] possible support for Gdx Ai #436
Replies: 2 comments 5 replies
-
Hey @ronjunevaldoz, I personally haven't used Gdx AI, so I don't feel qualified to provide utilities for it. I'm not against adding a module for another library though, since we already did something similar for VisUI and Ashley. If anyone would like to contribute utilities for Gdx AI, I can do thorough code review and offer some tips in terms of the API design. |
Beta Was this translation helpful? Give feedback.
-
Hello @czyzby, I was experimenting a bit and found it could be nice to have a dsl for gdxAI's behavior tree. Let me know what you think. I can find some time to work on the module for ktx. I'm not sure yet which utilities can be made for other parts like pathfinding and steering though. Suggestions are welcome. Example implementationtypealias GdxSequence<E> = com.badlogic.gdx.ai.btree.branch.Sequence<E>
inline fun <E> behaviorTree(rootTask: Task<E>? = null,
blackboard: E? = null,
init: (@GdxAiTaskDsl BehaviorTree<E>).() -> Unit = {}): BehaviorTree<E> {
contract { callsInPlace(init, InvocationKind.EXACTLY_ONCE) }
val behaviorTree = BehaviorTree(rootTask, blackboard)
behaviorTree.init()
return behaviorTree
}
inline fun <E> Task<E>.sequence(init: (@GdxAiTaskDsl Sequence<E>).() -> Unit = {}): GdxSequence<E> {
contract { callsInPlace(init, InvocationKind.EXACTLY_ONCE) }
val sequence = GdxSequence<E>()
addChild(sequence)
sequence.init()
return sequence
}
// Other Tasks and decorators...
Example usageclass Cat
class Sleep : LeafTask<Cat>()
// etc...
val catBtree = behaviorTree(rootTask = null, blackboard = Cat()) {
sequence {
untilSuccess {
sequence {
repeat(UniformIntegerDistribution(1, 3), Hunt())
addChild(Play())
}
}
addChild(Eat())
addChild(Sleep())
wait(2f)
addChild(Drink())
}
} It's also possible for users to write their own extension for whatever custom Task, so you don't need addChild(task). |
Beta Was this translation helpful? Give feedback.
-
Hi @czyzby are you planning to have a support for the gdx ai library?
Beta Was this translation helpful? Give feedback.
All reactions