Thanks Schorsh, I have found the answer, I was looking in the wrong place, well sort of. I had to slow down a video of Mario to see what was actually going on, then it became obvious. My code was correct, but because I was missing inertia/acceleration/deceleration it didn't behave the correct way.
Now when my character runs and jumps, when you attempt to go in the other direction you have too much forward momentum and thus cannot just move in mid-air in the opposite direction.
I haven't yet added the speeding up of the animation frames for running, i'll have to look into it.
My base code has changed, as I had to borrow from someone else's script to get it to work right. There's a few new additions that I don't quite yet understand, but I expect I will eventually, I am a noob after all.
Here's my modified code in case anyone needs it (change variables to suit):
# Mario Style Player Movement
extends KinematicBody2D
var bear_velocity = Vector2()
var on_ground = false
const ACCELERATION = 4
const MAX_SPEED = 110
const GRAVITY = 15
const FLOOR = Vector2(0,-1)
const JUMP_HEIGHT = -300
const MIN_JUMP_HEIGHT = -20
func _physics_process(delta):
# Add Gravity
bear_velocity.y += GRAVITY
var friction = false
# Walking Left, Right or Idle
if Input.is_action_pressed("ui_right"):
#$Sprite.flip_h = false
bear_velocity.x = min(bear_velocity.x +ACCELERATION, MAX_SPEED)
$Sprite.play("Walk")
elif Input.is_action_pressed("ui_left"):
#$Sprite.flip_h = true
bear_velocity.x = max(bear_velocity.x -ACCELERATION, -MAX_SPEED)
$Sprite.play("Walk")
else:
#bear_velocity.x = 0
friction = true
#if on_ground == true:
$Sprite.play("Idle")
# Jump
if is_on_floor():
if Input.is_action_just_pressed("ui_select"):
bear_velocity.y = JUMP_HEIGHT
if friction == true:
bear_velocity.x = lerp(bear_velocity.x, 0, .2)
else:
if bear_velocity.y < 0:
$Sprite.play("Jump")
else:
$Sprite.play("Fall")
bear_velocity.x = lerp(bear_velocity.x, 0, .05)
# Variable Height Jump
if Input.is_action_just_released("ui_select") && bear_velocity.y < MIN_JUMP_HEIGHT:
bear_velocity.y = MIN_JUMP_HEIGHT
# Sprite Direction
if bear_velocity.x > 0:
$Sprite.flip_h = false
elif bear_velocity.x < 0:
$Sprite.flip_h = true
# Add Movement from Vector2
bear_velocity = move_and_slide(bear_velocity, FLOOR, 5, 4, PI/3)