I am probably not going to be the last one that asks about this. I need a character like a kinematicbody2D, but one that responds to 2D physics.
As such, I am having a very hard time grasping how to move horizontally without physics, and vertically with physics simultaneously.
This was my attempt with just left and right movements, but the character kept sliding around like it was on ice (which isn’t in this first level at least, lol. Maybe it will be necessary later).
func _physics_process(delta):
if is_dead == false:
if Input.is_action_pressed("left") and not Input.is_action_pressed("right") and damaged == false:
motion.x = -SPEED
elif Input.is_action_pressed("right") and not Input.is_action_pressed("left") and damaged == false:
motion.x = SPEED
else:
motion.x = 0
func _integrate_forces(state):
if motion.x != 0:
add_central_force(motion * SPEED / 2)
My next attempt was to use linear velocity for movement and just stop all of the movement on the X axis, but this has proven to be impossible with the physics-based jumping mechanics. That code is very long and doesn’t really show what I am trying to do, so I’ll just add the jump if statement here from that code:
if Input.is_action_pressed("up") and on_ground == true and timeut == false:
motion.y = -JUMP_SPEED
apply_central_impulse(motion)
PS: physics would be necessary more later in the game, where the character swims, walks on surfaces of various frictions, accidentally ends up on a conveyor belt… All kinds of crazy stuff, but I won’t spoil it.