+2 votes

Hi all, so, as title reads, I'm trying to write a custom moveandslide function/method in GDScript that will, hopefully, do the exact same thing as the built-in moveandslide function for the KinematicBody2D class, except will accept delta as a parameter, rather than reaching for delta from
(Engine::get_singleton()->is_in_physics_frame() ? get_physics_process_delta_time() : get_process_delta_time())

The reason I'm doing this is because I'm writing a system that will build a node graph for games that are set in a 'platformer' type perspective, where an A* graph is not as easily produced. To be able to build this graph, I need to be able to simulate the actions of KinematicBody2D characters. The easiest way to do this seemed to me to be to call physicsprocess() within a loop, and supply an arbitrary delta (like 0.0166667 or something). The problem that I discovered fairly quickly in doing this was that moveandslide() or moveandslidewithsnap() does not actually read the delta parameter from physicsprocess(). So after doing some digging, I found that someone else had already desired to do such a thing here: https://github.com/godotengine/godot/pull/33653 and after reading the rather lengthy argument in the comments, user reduz at the bottom suggests:

Re-implementing your own moveandslide that fits your needs better is not a task of high difficulty. moveandslide is intended to be a wrapper over moveandcollide for the most common use cases, and this is clearly not a common use case, but it's not very complex. Its less than 100 lines of code you can easily re-implement in GDScript, C# or anything that meets your needs. If you can implement a client-server physics architecture, I fail to see how the complexity of this task can be above your head.

and

One thing we could do, is include an example of writing a moveandslide function in GDScript, that users can take and customize if they really want to.

So, while using the source as my template here: https://github.com/godotengine/godot/blob/master/scene/2d/physics_body_2d.cpp I tried to essentially copy the functionality and substitute the location where the method derives its delta with delta as a parameter.

This almost works, but there are two issues that I've encountered: the biggest issue is that within the Godot engine, I have no access to the KinematicBody2D's onwall, onfloor, or onceiling members/properties. The other issue, which may be a non-issue is that I can't find a way to duplicate the "separateraycast_shapes" method.

Does anybody have any strategies or ideas about how I might proceed with this?

in Engine by (25 points)

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.