I have done some exercises, but the collisions are not recognized, I have done it in several ways without success
Can you provide more details like code, screenshots or error messages so we can understand your problem?
I make a simple example, a main scene, place a staticbody there, place a collider2d and its shape.
then I instantiate the player that also has its collider, the shape.
When running the player does not make the ground collision.
the player code is the one provided by godot
extends CharacterBody2D
const SPEED = 300.0
const JUMP_VELOCITY = -400.0
func _physics_process(delta):
# Add the gravity.
if not is_on_floor():
velocity += get_gravity() * delta
# Handle jump.
if Input.is_action_just_pressed("ui_accept") 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("ui_left", "ui_right")
if direction:
velocity.x = direction * SPEED
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
move_and_slide()
Whats the collison layer and collision mask of the characterbody and staticbody?
Also you shouldnt have "Node"s in between of "Node2D"s in the scene-hierachy
thank you… I was able to solve it
1 Like