Hoi1! I'm having this weird problem where my player character (consisting of a Rigidbody2d parenting a rectangular CollisionShape2d) is falling slower than they should on:
- Running the project
- Falling of the platform (StaticBody2d) by themselves
The effect goes away when any of the keys that control the player (via code) is pressed. Speaking of, here's my entire code:
I've also seemed to stumble upon the fact that perhaps, this phenomenon is framerate dependent as it all but goes away when I try to record it. Still, I'll post one of my attempts, although the effect is barely noticable:extends RigidBody2D @export var target_speed = 250 @export var minimum_speed = 10 @export var acceleration_time = 1 @export var decceleration_time = 0.2 @export var turn_time = 0.5 var target_acceleration = 0 var move_direction = 0 @export var gravity = 980 var locomotive_forces = Vector2(0, 0) var external_forces = Vector2(0, 0) # Called when the node enters the scene tree for the first time. func _ready(): pass # Replace with function body. func _integrate_forces(state): external_forces = Vector2(0, gravity) for i in (state.get_contact_count() - 1): external_forces += state.get_contact_impulse(i) apply_central_force(locomotive_forces + external_forces) # Called every frame. 'delta' is the elapsed time since the previous frame. func _process(delta): if Input.is_action_pressed("move_left"): move_direction = -1 else: if Input.is_action_pressed("move_right"): move_direction = 1 else: move_direction = 0 if move_direction != 0: if sign(linear_velocity.x) == move_direction: if abs(linear_velocity.x) < target_speed: target_acceleration = target_speed / acceleration_time * move_direction else: target_acceleration = 0 else: target_acceleration = target_speed / turn_time * move_direction else: if abs(linear_velocity.x) < minimum_speed: linear_velocity.x = 0 target_acceleration = 0 else: target_acceleration = target_speed / decceleration_time * -linear_velocity.normalized().x ##get something better locomotive_forces.x = mass * target_acceleration - external_forces.x print_debug(locomotive_forces + external_forces) print_debug(sign(linear_velocity.x) == move_direction)