Hello, I am running in to an issue in the 2D Action Adventure for Godot, following through Udemy.
In Section 28 - “Pushing the Block” I am having an issue where when the player collides with the block it doesnt move while I am colliding with the block. Only when I release my keyboard button being pressed does the block move. It should be moving the entire time the player is colliding with the block. The block does move in the correct direction when the keyboard button is released but no movement at ll when pressed.
Block Scene:
RigidBody2D > CollisionShape2D > Sprite2D
RigidBody2D
Mass = 1kg
Gravity = 0
Lock Rotation = On
Damp = 15
CollisionShape2D
Shape = RectangleShape2D
Size = 16x16
Player Scene
extends CharacterBody2D
class_name Player
@export var move_speed: float = 100
@export var push_strength: float = 10
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
position = SceneManager.player_spawn_position
pass
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
var move_vector: Vector2 = Input.get_vector("move_left", "move_right", "move_up", "move_down")
velocity = move_vector * move_speed
if velocity.x > 0:
$AnimatedSprite2D.play("move_right")
elif velocity.x < 0:
$AnimatedSprite2D.play("move_left")
elif velocity.y > 0:
$AnimatedSprite2D.play("move_down")
elif velocity.y < 0:
$AnimatedSprite2D.play("move_up")
else:
$AnimatedSprite2D.stop()
#get the last collision
#Check if it is the Block object
#If it is the Block Object, push it
var collision: KinematicCollision2D = get_last_slide_collision()
if collision:
var collider_node = collision.get_collider()
if collider_node is RigidBody2D:
var collision_normal: Vector2 = collision.get_normal()
collider_node.apply_central_force(-collision_normal * push_strength)
#takes velocity to move player
move_and_slide()