Character controller without relying on built-in physics?

AerosolSPAerosolSP Posts: 1Member

Hello and welcome to my thread.

I have a...disdain for built-in physics systems when it comes to 2D games. What is the best way to go about creating a character controller in Godot without relying on built-in physics?

I'll describe in detail what I mean. Rather than apply an impulse or a vector on an object, I want to use deltaTime and be able to say that for every 60th of a second the right arrow button is pressed down, 0.001 is added to my player object's acceleration value. And that acceleration value, in turn, is used to say something along the lines of:

"Hey, Godot. Set the player's x position to whatever it is right now, plus the acceleration value."

And when it comes to checking for collisions, I'd like to be able to just refer to points in relation to the origin of the play object, and say something like:

"Hey, Godot. Check and see what is at 10 pixels to the right of the player's x position before you move anything. If there's a wall, just...don't put the player in there please? Kthx".

What's the best way to go about this in Godot? Just point me in the right direction so I can focus my attention on the right materials. Thanks a mill.

Answers

  • KalahertyKalaherty Posts: 5Member

    I'm not sure if this is what you want, but I'd recommend looking up "set_process" and "_process(delta)", which will allow you to update a node per frame without use of the internal physics engine.

    For checking nodes against each other, I'd create an empty node and place the game objects as children under that node. That way you can just loop through its children and do a quick logical compare to make sure that you don't check anything against itself.

    It shouldn't be much of a hassle at all, but I would be concerned about potential slow downs depending on how complicated your collision code is since it's running through a scripting language... But who knows, GDscript seems pretty fast and a simple AABB test rules a lot out.

    I hope that helps and points you in the right direction. I'm a bit tired and sick, so I hope it made sense.

  • SomnivoreSomnivore Posts: 102Member

    Use a KinematicBody2D

    In your _fixed_process callback, you would var move = move(velocity), then slide along your collisions using their normals. You move your body using move(), supplying how much movement you want (e.g. with velocity); it returns how much movement was left over before the body was stopped, giving you an opportunity to slide along the surface you collided with or do whatever you mean to, and then move again, until you've moved more than you're willing to calculate for every physics frame, or you're not colliding anymore.

Sign In or Register to comment.