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?