- Edited
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.