Hello everyone I would like to create the game of my dreams, and this is my first project, so I’m still new to programming.
Please help me with the code. I tried to replicate the Celeste mechanics where a player can be blown away by the wind as a separate force that acts on the player’s direction. I’m stuck, so any help would be greatly appreciated. Thank you.
extends CharacterBody2D
const JUMP_VELOCITY = -400.0
@export var SPEED = 250.0
@export var boost = 15
var jerk_speed : float
the speed of the player himself
var speed_plaer : Vector2
#additional player speed
var speed_bost : Vector2 = Vector2(20, 8)
var direction : Vector2 = Vector2.ZERO
Get the gravity from the project settings to be synced with RigidBody nodes.
var gravity = ProjectSettings.get_setting(“physics/2d/default_gravity”)
func _physics_process(delta):
direction = Input.get_vector("Left", "Right", "Up", "Down")
if not is_on_floor():
velocity.y += gravity * delta
# Handle jump.
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
velocity.y = JUMP_VELOCITY
velocity.x = speed_plaer.x + speed_bost.x
if direction.x >= 0.5 :
speed_plaer.x = clamp(min(velocity.x+ boost, SPEED), -SPEED, SPEED)
elif direction.x <= -0.5 :
speed_plaer.x = clamp(max(velocity.x- boost, -SPEED), -SPEED, SPEED)
elif direction.x == 0 and is_on_floor():
speed_plaer.x = move_toward(speed_plaer.x, 0, 90)
elif direction.x == 0 and not is_on_floor():
speed_plaer.x = move_toward(speed_plaer.x, 0, 5)
move_and_slide()