#Collision problem with my map
1 messages · Page 1 of 1 (latest)
Based on your first screenshot it looks like your character is already intersecting the ground collilder. Move them up so theyre above the collider and it should no longer fall through the floor assuming all other settings are correct such as collision layers.
Ah, I think I see it now. You are using an Area2D node for the ground and wall colliders. Change the Area2D node type to StaticBody2D.
post your script attached to the player
All right
extends CharacterBody2D
#State Machine
@export var state_machine: LimboHSM
#States
@onready var idle_without_katana: LimboState = $LimboHSM/Idle_without_katana
@onready var walking_state: LimboState = $LimboHSM/WalkingState
@onready var dodge_backwards: LimboState = $"LimboHSM/Dodge backwards"
@onready var blocking_1: LimboState = $"LimboHSM/Blocking 1"
@onready var blocking_2: LimboState = $"LimboHSM/Blocking 2"
@onready var running_animation: LimboState = $"LimboHSM/Running animation"
@onready var basic_attack: LimboState = $"LimboHSM/Basic attack"
@onready var death: LimboState = $LimboHSM/Death
@onready var posture_break: LimboState = $"LimboHSM/Posture break"
@onready var drawing_sword: LimboState = $"LimboHSM/Drawing sword"
@onready var special_attack: LimboState = $"LimboHSM/Special attack"
@onready var phase_2_transition: LimboState = $"LimboHSM/Phase 2 transition"
@onready var idle_with_katana: LimboState = $"LimboHSM/idle with katana"
const SPEED = 300.0
const JUMP_VELOCITY = -400.0
var movement_input:= Input.get_axis("Left", "Right")
func _ready():
_initialize_state_machine()
func _initialize_state_machine():
#Define state transition
state_machine.add_transition(idle_without_katana, walking_state, "to_move")
#Mise en place State Machine
state_machine.initial_state = idle_without_katana
state_machine.initialize(self)
state_machine.set_active(true)
pass
func _physics_process(delta: float) -> void:
# Add the gravity.
if not is_on_floor():
velocity += get_gravity() * delta
move_and_slide()```
Hmm. Double check the collision layers for your character and the ground static body to make sure they can interact with each other.
Other than that the only thing it could be is something inside the state machine applying gravity of some kind.
I created a basic test scene similar to yourset using the CharacterBody2D template and it works without falling through the floor.
Strange
Layer 1: Map layer 2: player
My player is set to layer 1 and the map + wall and ground to layer 2
How do you copy and paste your script like that into discord?
you put 3 " ` " before and after you pasted your script
But i set it up well in my settings
I don't really understand why it's falling
You have them on separate layers it sounds like.
Post a screenshot of which layer and mask both your player and the ground colliders are on just to verify.
All right
Yep thats the problem. Read up on godot collision layers and masks so you understand them better but I'll give you the tldr;
Layer 1: Map; Layer 2: Player
Basically a mask filters which layer that node can "see" So because your Ground is on layer 1 and your player is only filtering for layer 1, it doesn't "see" it so it won't interact.
If you make both of them layer 1, like in my example is should work
Ah i understand better
I will tell you right now if it works
Uh i just have a little bug in my code i fix it rq
Still falling
You have both the ground and player collision layer and mask all set to layer 1? You are using a StaticBody2D for the ground correct?
And your player is not starting the scene already intersecting with the ground.
Exactly what you told me to do
If all of that is correct I'm not sure how to troubleshoot this any further.
well CharacterBody2D.move_and_slide will take gravity into account but it should still stop on top of the ground.
Unless something was changed in the project settings that could interfere with this having that simple setup I described will work.
Thats just renaming them so thats fine.
Thats my whole test scene. Default everything, using the CharacterBody2D template script.
Yep, which is why I'm confused. You did set your layers for both the character and player to be only using layer 1 for the collision and mask right?
Only layer 1 and mask 1 for everything, it maybe come from the script or something else
But i have noticed that collisionshape2D on the player node is blue but on the map it's white
Possible. If everything is the same as my test scene then the issue has to be coming from another script.
iirc thats just how colliders are colored within instanced scenes. But maybe double check that all the collision related nodes in the player scene are set to process_mode inherit.