Godot V.4.1.2
WINDOWS 11
2D GAME

Heya.

So I'm working on a 2D, horizonal-scrolling, jump only platformer in Godot v4.1.2

My Player is a CharacterBody2D with a CollisionShape2D and other necessary nodes.

This is the entire Player Script:

extends CharacterBody2D

const SPEED = 1000.0
const JUMP_VELOCITY = -2000.0
const jump_pressed_remember_time:float = 0.1
@export var cut_jump_height:float = 1
var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")
var jump_pressed_remember : float
var rotation_speed = 5 # for the falling animation.

func _process(_delta):
	# Code for Camera to follow properly
	$Camera2D.global_position.y = $Camera2D.global_position.y
	$Camera2D.drag_horizontal_enabled = true


func _physics_process(delta):
	jump_pressed_remember -= delta
	
	# Add the gravity.
	if not is_on_floor():
		$AnimatedSprite2D.play("falling")
		velocity.y += gravity * 2 * delta
	
	# Entire Jump Code
	if Input.is_action_pressed("jump"):
		jump_pressed_remember = jump_pressed_remember_time
		if is_on_floor():
			$AnimatedSprite2D.rotation_degrees = -20
	if(jump_pressed_remember > 0) and is_on_floor():
		jump_pressed_remember = 0
		velocity.y = JUMP_VELOCITY


	# Jump control thingy.
	if velocity.y < -1000 and Input.is_action_just_released("jump"):
		velocity.y = -1000
	velocity.x = SPEED
	
	# rotate 20 degrees smoothly when falling
	if velocity.y > -1000 and !is_on_floor():
		$AnimatedSprite2D.rotation= lerp_angle($AnimatedSprite2D.rotation, deg_to_rad(20), rotation_speed * delta)


	move_and_slide()
	
	# Rotating the Player with the ground
	if(is_on_floor()):
		$AnimatedSprite2D.play("running")
		var normal:Vector2 = get_floor_normal()
		var offset: float = PI / 2
		$AnimatedSprite2D.rotation = normal.angle() + offset

The collision of player is a small box because we're just rotating the sprite, and a wider collision box makes it kinda offset. and there's no issue in making it taller, its just that i kept it like that. if it works, it work 👍.

And the video is the gameplay of the prototype (my pc is being slow again, so i had to enable movie maker to atleast get the gameplay footage. oof (-_-''') ) VIDEO LINK GO HERE

The curved terrain is based on a youtube video on making curved terrain in Godot 4

(tl;dr - basically a staticbody2d with path2d as a outline of the curved terrain, and a script in it to make its line2d, collisionpolygon2d and polygon2d to change its polygon into the same as that of path2d.)

As you can see the player is jittering as it moves downwards. the steeper it is, the slower but visible the jitter.

I think it's because of the tremendous speed and gravity. kinda like you sliding from a stairs inside a cardboard box thing (because its fun)

Is there a solution to remove this jittering? what should i do?

cheers!
stik.

kuligs2 I tried, but it still gives the same result. I tried circle and capsule too, but still the same issue with no change.

A thing I've to highlight is that I think the issue could be because when the player moves, he would be away a bit from the terrain, and again gravity pulls him and he touches ground. That means he would be not touching the ground for a fraction of seconds.

I tried increasing the gravity, but at a point, the gameplay wont feel right.

Maybe I kind of need a solution which would let my player attach with the ground while sliding, and maybe set a limit angle for that (eg- 45 degrees). I tried finding such a solution, but I couldn't find such way. Do anyone know any alternative solution?

PS: the jittering is actually animation change from fall to run animations (for people who've wondering) which kind of proves my theory for the reason of jittering. And no, I cant change the animations or whatsoever, this issue would still remain, and if I'm supposed to put, say, fall particles, it would just go bonkers 🤣.

    6 months later

    mrstik101

    Alright, bit late, but find the solution
    https://docs.godotengine.org/en/stable/classes/class_characterbody2d.html#class-characterbody2d-property-floor-max-angle

    the floor max angle is a value where the body will consider the touching surface a floor until a certain angle. And I increased the value a lit bit with my comfortability.

    Can't show the code though, because rn im in school pc

    EDIT: Sorry, that ain't professional at all, but here's a post that explains my point: https://forum.godotengine.org/t/how-to-make-a-character-a-square-to-rotate-along-side-the-slope-it-is-on-2d-platform/10166

    So, happy journey with your game dev, since a road block with this one is gone!
    toodles