Godot Version
4.5.1
Question
Hi, I have two CharacterBody2D nodes, let’s call them A and B. In A I am detecting collisions like this.
var collided = move_and_slide()
if collided:
for i in range(get_slide_collision_count()):
var collision = get_slide_collision(i)
var collider = collision.get_collider()
This works fine if B is stationary. However, when B has a downward velocity and is above A, it traps A from above. A can no longer move, and even if I have set A’s velocity to have an upward component before using move_and_slide(), the code above will not detect B. It is as if the y component of the velocity is being zeroed out before any collisions are detected. What is the proper way to detect this?
For more context, in this case A is my player and B is a physics object above them. I want for A’s script to be able to detect B and, if conditions are met, set the velocity of B to be the same as the velocity as A so that it moves up when A jumps. What’s the easiest way to do this?
1 Like
The CharacterBody2D may think another body below it is a “moving platform”, you could prevent this by changing the platform_floor_layers property
1 Like
Hmm, OK, thanks. I ended up reworking it so I don’t have to solve this problem.
1 Like
That is a perfectly valid route to take. But beware of avoiding problems, it often indicates either a deeper problem that will rear itself again in the future, or a lack of clarity on what you were doing which again, will probably rear itself up again in the future.
I know that sometimes it seems easier to work around a problem, and that is perfectly valid, but if you have the time, it is well worth working out why you were getting unexpected behaviour anyway. It is 99.9% of the time not an engine failing or an engine bug, but something you or your code was assuming that wasn’t the case. Always worth working out what that was, if only so that in the future you know what to look for when it inevitably arises again.
1 Like
Thanks, I agree in general with that advice 
2 Likes
Umm hello…
… i am Also facing same problem of collision.. actually my enemy overlaps my player and my plyer overlap Also.
So i use regit body for my enemy so that they can collide with character body.. but still the results are not that good.
func move_forword(delta):
var distance = global_position.distance_to(player.global_position)
if distance > 250:
global_position += transform.y \* -speed \* delta
elif distance < 250:
global_position += transform.y \* speed \* delta
moving = true
fule_reduce()
check_fule()
I m using this for keeping a safe distance between them…
If you have a good solution please share 

Just noticed your question! Sorry, I’m not sure exactly what the problem is you’re describing. In my case, I was trying to get my PlayerController2D to be able to slide underneath a RigidBody2D that was above it. I ended up putting a a StaticBody2D over my character that would support objects rather than trying to get the CharacterBody2D to see and compensate for the object above it.
1 Like
Well in simple way .. my player and enemies get overlapped by eachother.. mostly enemies overlap player.. i just want it collide and move instead of overlap.. i used static bodies Also but didn’t worked. Even switched enemies to regit body but didn’t not work.. so i think to use this as a oppertunity. And increase the damages whenever they overlap. Now it’s a attack type of My enemy not a problem.
