Godot Version
Godot_v4.2.2-stable_win64
Question
As the title suggests, I’m following the latest Brackeys Godot Beginner Tutorial, and I’ve encountered an issue where my slime character keeps running between the walls. I’d appreciate it if you could watch the video below for better context and offer some guidance.
Can you post some screen shots of your project and post relevant sections of your code?
This would be helpful for us to help you.
1 Like
For future posts: Said video is 80minutes long. Don’t expect someone to watch that just to help you.
Instead post your code as text, show screenshots of your scenes, any errors or videos of things happening that shouldn’t happen. This greatly increases your chances for an answer.
2 Likes
yeah i will its just that i was not allowed to add attachments cause i was new to the platform
You can still share your code. Also can you link to a video uploaded on youtube?
Here, I have uploaded it for everyone to see without following the link.
Can you also share what you think are the relevant scripts?
If you paste them in here, use the “preformatted text” option so it looks nice.
1 Like
here is the script for slime:
extends Node2D
# Called when the node enters the scene tree for the first time.
const speed=60
var direction =-1
@onready var ray_castright = $RayCastright
@onready var ray_castleft = $RayCastleft
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
if ray_castleft.is_colliding():
direction=-1
if ray_castright.is_colliding():
direction=1
position.x += direction * speed * delta
1 Like
the script for game :
extends CharacterBody2D
const SPEED = 100.0
const JUMP_VELOCITY = -300.0
# 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):
# Add the gravity.
if not is_on_floor():
velocity.y += gravity * delta
# Handle jump.
if Input.is_action_just_pressed("jump") and is_on_floor():
velocity.y = JUMP_VELOCITY
# Get the input direction and handle the movement/deceleration.
# As good practice, you should replace UI actions with custom gameplay actions.
var direction = Input.get_axis("move_left", "move_right")
if direction:
velocity.x = direction * SPEED
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
move_and_slide()`Preformatted text`
1 Like