#Collision problem with my map

1 messages · Page 1 of 1 (latest)

raven flume
#

Hello everyone, i have a problem with my collisions. Every time i launch the game (DEBUG mode), my character is always falling, and i put collisions shapes everywhere i don't understand

#

And his collisions shape is not deactivated

wraith moat
#

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.

raven flume
#

I tried that and unfortunately it remains the same

#

He still falls

wraith moat
#

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.

raven flume
#

Oh let me try this i will tell you if it works

#

It doesn't work 😦 he still falls

wraith moat
#

post your script attached to the player

raven flume
#

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()```
wraith moat
#

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.

raven flume
#

Strange

#

Layer 1: Map layer 2: player

#

My player is set to layer 1 and the map + wall and ground to layer 2

wraith moat
#

thats sounds like your issue if theyre on separate layers.

low bolt
#

How do you copy and paste your script like that into discord?

raven flume
#

you put 3 " ` " before and after you pasted your script

raven flume
#

I don't really understand why it's falling

wraith moat
#

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.

raven flume
#

All right

wraith moat
#

My Player

#

My Ground

raven flume
#

My player:

#

My Ground and walls:

wraith moat
#

Yep thats the problem. Read up on godot collision layers and masks so you understand them better but I'll give you the tldr;

raven flume
#

Layer 1: Map; Layer 2: Player

wraith moat
#

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

raven flume
#

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

wraith moat
#

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.

raven flume
#

Exactly what you told me to do

wraith moat
#

If all of that is correct I'm not sure how to troubleshoot this any further.

raven flume
#

Is it because of gravity ?

wraith moat
#

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.

raven flume
#

My layers settings

wraith moat
#

Thats just renaming them so thats fine.

#

Thats my whole test scene. Default everything, using the CharacterBody2D template script.

raven flume
#

And that's mine:

#

We have the almost the same thing

wraith moat
#

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?

raven flume
#

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

wraith moat
#

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.

raven flume
#

It's all good

#

IT WORKS !

#

haha

#

I just had to remove the former collisionshape

#

I disabled it to specific animations but i did it badly and it ended up messing with my character

#

Thank you very much for your help

wraith moat
#

Awesome! glad you got it working

#

Good luck on your game!