- Edited
Hi. I'm new here, and I'm making a platformer game. I'm trying to make it so my character sticks to sloped tiles instead of bouncing down them, and the speed at which it travels up and down them is fixed, rather than appears to be affected by gravity.
I've looked at move_and_slide_with_snap and tried to reverse engineer the 2D Platformer Demo (KinematicBody) but I can't get my head round it. Can anybody help?
Here's a video of what I'm experiencing:
https://youtube.com/watch?v=zi_cJEP5l-Y
This is my basic code (I'm currently working on a state machine, coyote time and wall climbing stuff):
extends KinematicBody2D
export (int) var speed = 400
export (int) var jump_speed = -700
export (int) var gravity = 3000
export (float, 0, 1.0) var friction = 0.25
export (float, 0, 1.0) var acceleration = 0.25
var velocity = Vector2.ZERO
func _physics_process(delta):
var direction = 0
if Input.is_action_pressed("right"):
direction += 1
if Input.is_action_pressed("left"):
direction -= 1
if direction != 0:
velocity.x = lerp(velocity.x, direction * speed, acceleration)
else:
velocity.x = lerp(velocity.x, 0, friction)
$Sprite.flip_h = velocity.x < 0
velocity.y += gravity * delta
velocity = move_and_slide(velocity, Vector2.UP,true, 4)
if Input.is_action_just_pressed("jump"):
if is_on_floor():
velocity.y = jump_speed
Thanks for looking :)
Some background to this, if you are at all interested...
I said that I'm new here, but in fact I'm pretty new to game development too. I messed about with RPG Maker years ago, and last year during lockdown I got GameMaker Studio 2 and set about building my 'dream' platform game. Unfortunately, I bounced hard off that software, due to its horrendous UI, unnecessarily convoluted approach and restrictive licensing. I discovered Godot, but put on hold any game dev ambitions in the Summer as it got in the way of my work as a web developer (or vice versa!).
A year on and I'm giving it another shot and am underway with my platformer again, and so far am pretty pleased with the results - and with Godot, which is so much more elegant than GMS2.
Here's a video of what I previously did in GMS2: